tags:

views:

165

answers:

5

I'm trying to backup a folder containing several folders and files to a remote location (will be uploading zipped files). Is there any existing scripts that may help me, which checks if the files have been modified after the date of the last backup, and only backs up files created / modified after that?

The current size of the data is around 1gb, and I expect adding 50mb-200mb each month

Also, what would be the best way to extract the state of the files on a specific date?

+2  A: 

I would use Subversion for this. If you have a shell on the remote system then its easy to do this with a cron job.

If you have a shared host then you could automate this process over sftp/ftp by mounting the remote drive (maybe with fuse) and then run a svn commit via cron job.

Rook
+1  A: 

I don't think anything like this exists.

First, you'll need some recursive function to find all the files in a directory and all the sub directories. There are a lot of examples for that problem. The idea is to use the scandir() function recursively

Then for each file found, you'll need to check if the file has been modified since your last backup, and if it has been modified, ad it to the list of files to backup. You could do something like:

if (filemtime($filename) > $last_backup_time)
{
    $files_to_backup[] = $filename;
}

Finally, for each file to backup, you just have to copy() or ftp_put() your archive of modified files.

analogue
The RecursiveDirectoryIterator from the SPL is a much nicer way than recursive scandir calls ;)http://stackoverflow.com/questions/2418068/php-spl-recursivedirectoryiterator-recursiveiteratoriterator-retrieving-the-full
Tobias P.
You can also execute rdiff command for that also. See http://en.wikipedia.org/wiki/Rsync#Variations
redben
+1  A: 

incremental backup script using php:

http://web4u.mirrors.phpclasses.org/package/4841-PHP-Manage-backup-copies-of-files-.html

ftrotter
+1  A: 

You can call/execute rsync from php, rsync is a command that synchronizes to remote directories, as its name implies. The good thing about rsync is that it only adds new resources, send only diffs on updated resource, and deletes anything that is not on the source directory (if you want it too). Note that with this you don't have incremental backups. For that you should use a VCS (Git, SVN or CVS) as stated on other answers.

Here is a step by step rsync+php tutorial for using it from within php

redben
A: 

Instead of rsync you could consider rdiff-backup. Using rsync techniques, it's able to make incremental remote backups. Git is also possible to do this, but the downside is that you can't remove older incrementals from the repository (due to Gits nature).

I don't see why you'd write your own solution, while other excellent solutions already exist.

Bram Schoenmakers