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.

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.