Jump to content

File Backup Script - Run only if file size changed


TripleDES

Recommended Posts

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.