Skip to content

Instantly share code, notes, and snippets.

@daangemist
Created July 8, 2014 07:01
Show Gist options
  • Save daangemist/a1e20998fcaef4fd7cf4 to your computer and use it in GitHub Desktop.
Save daangemist/a1e20998fcaef4fd7cf4 to your computer and use it in GitHub Desktop.
Periodically backups a file
<?php
if( $argc === 1 ) {
die('Will periodically backup a file. Usage: php ' . $argv[0] . ' filename' . PHP_EOL);
}
$filename = $argv[1];
if( !file_exists($filename) )
die('File ' . $filename . ' not found.' . PHP_EOL);
$backupEverySeconds = 60*30; //backup every half hour
$lastBackup = 0;
while( true ) {
if( (time() - $backupEverySeconds) > $lastBackup ) {
//perform the backup
$newFilename = $filename . date('YmdHis');
copy($filename, $newFilename);
$lastBackup = time();
}
sleep(180);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment