Skip to content

Instantly share code, notes, and snippets.

@bitbybit
Created June 10, 2013 12:24
Show Gist options
  • Save bitbybit/5748349 to your computer and use it in GitHub Desktop.
Save bitbybit/5748349 to your computer and use it in GitHub Desktop.
Backup rotation from remote server
<?
$dir = '/path/to/local/dir';
if(is_dir($dir)) {
date_default_timezone_set('Europe/Moscow');
$backup = fopen($dir.date("Y_m_d_H-i-s").'.tgz','w');
$archive = curl_init();
curl_setopt($archive,CURLOPT_URL,"http://url.to/backup.tgz");
curl_setopt($archive,CURLOPT_TIMEOUT,5);
curl_setopt($archive,CURLOPT_FILE,$backup);
// curl_setopt($archive,CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
// curl_setopt($archive,CURLOPT_USERPWD,"username:pass");
curl_exec($archive);
curl_close($archive);
fclose($backup);
unset($archive);
if($archives = opendir($dir)) {
while($archive = readdir($archives)) {
if(!is_dir($dir.$archive)) {
if(filemtime($dir.$archive) < strtotime('-30 days')) {
unlink($dir.$archive);
}
}
}
closedir($archives);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment