TripleDES Posted February 11, 2008 Share Posted February 11, 2008 I have a backup script for a particular file that is constantly updated. However, I only want the backup to be executed if the file size changes. What's a good way for me to check the 159302 Jan 23 00:10 file.20080123.tgz 159893 Jan 25 13:16 file.20080124.tgz 159377 Jan 25 14:31 file.20080125.tgz 1. Check the last file by date. 2. Check file size 3. Create new backup if file size != previous file. Any opinions on this matter? I currently have it checking today's date and yesterday's date. There's a flaw with this method since if a backup wasn't created because of a previous size match, then a backup will always occur every other day even if the file size doesn't change. ie. Feb 01 100k file.200800201.tgz Feb 02 - 100k - same size no change Feb 03 100k file.200800203.tgz - This is because yesterday file size = 0, thus new file is created. Link to comment https://forums.phpfreaks.com/topic/90520-file-backup-script-run-only-if-file-size-changed/ Share on other sites More sharing options...
Stooney Posted February 11, 2008 Share Posted February 11, 2008 Store all of the file information in a database. Whenever the backup script runs it compares the file sizes of the files with what's in the database and acts accordingly. To open a directory and read the files (pulled this from php.net) <?php $dir = "/etc/php5/"; // Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo "filename: $file : filetype: " . filetype($dir . $file) . "\n"; } closedir($dh); } } ?> For filesize you can just filesize($dir.$file); http://us.php.net/open_dir Link to comment https://forums.phpfreaks.com/topic/90520-file-backup-script-run-only-if-file-size-changed/#findComment-464100 Share on other sites More sharing options...
TripleDES Posted February 14, 2008 Author Share Posted February 14, 2008 Thanks, but storing file information in a db is a little more complicated than I want to make it. Link to comment https://forums.phpfreaks.com/topic/90520-file-backup-script-run-only-if-file-size-changed/#findComment-467115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.