简体   繁体   中英

Transfer Files from Rackspace CloudSite to Cloud Files

Just wondering if anyone knows of a prewritten php script to to transfer files from rackspace cloud site to rackspace cloud files.

Rackspace does provide a script to backup files to the cloud but not transfer . (and I only realized that after spending a couple of hours and finally getting the script working).

http://www.rackspace.com/knowledge_center/article/how-to-use-cron-to-backup-cloudsites-to-cloudfiles

I don't know PHP (which is required for Rackspace cron jobs), so if there's a script that would help me with this it would be great.

Thanks.

Below is the script I use when I backup to rackspace. It uses the php cloud files master library from racker labs. I set it up as a simple cron. Simply replace the emai

php 'path/to/backup.php'

<?

require_once('php-cloudfiles-master/cloudfiles.php');

$server_name = 'YOUR_SERVER_NAME'; //Name of the Current Server
$curr_date_time = date("Y-m-d--H:i:s"); //DON' CHANGE - Date
$curr_day = date("Yd"); //DON' CHANGE - Date
$sites = array("ENTERDATABASES HERE IN ARRAY FORMAT"); //Array of Databases to be Backed up
$site_root = "/var/www/";
$temp_dir = "/bak/mysql/"; //temp directory
$site_temp_dir = "/bak/site/"; //temp directory
$rscfUsername = 'YOUR RACKSPACE USERNAME'; // the username for your rackspace account
$rscfApiKey = 'YOUR RACKSPACE API KEY'; // the api key for your account
$rscfContainer = 'YOUR RACKSPACE CONTAINER'; //rackspace containr
foreach($sites as $site) {

try{

 exec("tar -czpf {$site_temp_dir}{$site}{$curr_date_time}_site.tar.gz {$site_root}{$site}");
 // check if the file is created
 if(file_exists("{$site_temp_dir}{$site}{$curr_date_time}_site.tar.gz")) {

 $auth = new CF_Authentication($rscfUsername, $rscfApiKey);
 $auth->ssl_use_cabundle();
 $auth->authenticate();
 $conn = new CF_Connection($auth);
 $conn->ssl_use_cabundle();

 // I allready created a container with this name otherwise user create_container
 $container = $conn->get_container($rscfContainer);

 // make a unique name with date in it so you know when it was created
 $objectName = $site.$curr_date_time.'.tar.gz';
 $store = $container->create_object($objectName);
 $store->load_from_filename("{$site_temp_dir}{$site}{$curr_date_time}_site.tar.gz"); // send to rackspace


 }

 } catch (Exception $e) {
     print_r($e, true);
 }

}

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM