$link = mysqli_connect($endpoint, "controller", "letmein888", "customerrecords") or die("Error " . mysqli_error($link)); /* Checking the database connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } $uploaddir = '/tmp/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $backup = uniqid("dbBackup", false); $backupfile = $uploaddir . $backup . '.' . 'sql'; $dbuser = "******"; $dbpass = "******"; echo $dbuser; echo $dbpass; $sqlcommand = "mysqldump --user={$dbuser} --password={$dbpass} --host={$endpoint} customerrecords > {$backupfile}"; echo $sqlcommand; exec($sqlcommand); $s3 = new Aws\S3\S3Client(['version' => 'latest', 'region' => 'us-east-1']); $bucket = uniqid("database-backup-", false); # AWS PHP SDK version 3 create bucket $result = $s3->createBucket(['ACL' => 'public-read', 'Bucket' => $bucket]); $s3->waitUntil('BucketExists', array('Bucket' => $bucket)); # PHP version 3 $result = $s3->putObject(['ACL' => 'public-read', 'Bucket' => $bucket, 'Key' => $backupfile, 'SourceFile' => $backupfile]); $expiration = $s3->putBucketLifecycleConfiguration(['Bucket' => $bucket, 'LifecycleConfiguration' => ['Rules' => [['Expiration' => ['Date' => '2015-12-25'], 'Prefix' => ' ', 'Status' => 'Enabled']]]]); $sqlurl = $result['ObjectURL']; echo $sqlurl; echo "Database backup created successfully and stored in the s3 bucket."; ?>
$rds = new Aws\Rds\RdsClient(['version' => 'latest', 'region' => 'us-east-1']); $resultrdb = $rds->describeDBInstances(array('DBInstanceIdentifier' => 'mp1SKread-replica')); $endpointrdb = $resultrdb['DBInstances'][0]['Endpoint']['Address']; echo "============\n" . $endpointrdb . "================"; $linkrdb = mysqli_connect($endpointrdb, "testconnection1", "testconnection1", "Project1"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } else { echo "Connection to RDB Success"; } $backupFile = '/tmp/FinalProjectDB' . date("Y-m-d-H-i-s") . '.gz'; $command = "mysqldump --opt -h {$endpointrdb} -u testconnection1 -ptestconnection1 Project1 | gzip > {$backupFile}"; exec($command); echo "success"; $s3 = new Aws\S3\S3Client(['version' => 'latest', 'region' => 'us-east-1']); $bucket = 'snehatestproject-' . rand() . '-dbdump'; if (!$s3->doesBucketExist($bucket)) { $result = $s3->createBucket(['ACL' => 'public-read', 'Bucket' => $bucket]); $s3->waitUntil('BucketExists', array('Bucket' => $bucket)); echo "{$bucket} Created Successfully"; } $result = $s3->putObject(['ACL' => 'public-read', 'Bucket' => $bucket, 'Key' => $backupFile, 'SourceFile' => $backupFile]); $result = $s3->putBucketLifecycleConfiguration(['Bucket' => $bucket, 'LifecycleConfiguration' => ['Rules' => [['Expiration' => ['Days' => 2], 'NoncurrentVersionExpiration' => ['NoncurrentDays' => 2], 'Prefix' => '', 'Status' => 'Enabled']]]]); echo "backup success"; $url = $result['ObjectURL']; echo $url; $urlintro = "index.php"; header('Location: ' . $urlintro, true); die; $linkrdb->close();
} else { header("location: gallery.php"); } echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; require 'vendor/autoload.php'; $s3 = new Aws\S3\S3Client(['version' => 'latest', 'region' => 'us-west-2']); #print_r($s3); $bucket = uniqid("nandinibuckettest", false); echo $bucket; # AWS PHP SDK version 3 create bucket $result = $s3->createBucket(['ACL' => 'public-read', 'Bucket' => $bucket]); # PHP version 3 $result = $s3->putObject(['ACL' => 'public-read', 'Bucket' => $bucket, 'Key' => $fname, 'SourceFile' => $uploadfile]); $objectrule = $s3->putBucketLifecycleConfiguration(['Bucket' => $bucket, 'LifecycleConfiguration' => ['Rules' => [['Expiration' => ['Date' => '2015-12-24'], 'Prefix' => ' ', 'Status' => 'Enabled']]]]); $url = $result['ObjectURL']; echo $url; $rds = new Aws\Rds\RdsClient(['version' => 'latest', 'region' => 'us-west-2']); $result = $rds->describeDBInstances(['DBInstanceIdentifier' => 'Project1db']); $endpoint = $result['DBInstances'][0]['Endpoint']['Address']; echo "============\n" . $endpoint . "================"; $link = mysqli_connect($endpoint, "nandini", "nandinipwd", "Project1db") or die("Error " . mysqli_error($link)); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } /* Prepared statement, stage 1: prepare */ if (!($stmt = $link->prepare("INSERT INTO Projectrec (uname, email, phone, raws3url, finisheds3url, jpegfilename, state, DateTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"))) { echo "Prepare failed: (" . $link->errno . ") " . $link->error;