Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

i'm using Incremental backup on my Server which means Every 1 MB will take another 1 MB as a backup

my problem is every time i delete a file i have to delete it also from the backup folder ... sometimes not me who delete the files

which means there will be too many un-needed files and folders not deleted ... what i want is making a synchronization script

between 2 folders (/home,/backup) but it seems to be a hard thing to do if i have to open each folder to check the files inside and close it etc... you know

can you give me a good idea how to do it ??

Kind Regards

Replies are listed 'Best First'.
Re: Incremental Backup
by sk (Curate) on Aug 25, 2005 at 06:46 UTC
    This node should give you info on how to sync files files sync

      hi

      Thanks alot , That works !!

      #!/usr/bin/perl -w use strict; use FILE::DirSync; my $dirsync = new File::DirSync { verbose => 1, nocache => 1, localmode => 0, }; $dirsync->src("home"); $dirsync->dst("backup"); $dirsync->dirsync();
Re: Incremental Backup
by neniro (Priest) on Aug 25, 2005 at 07:16 UTC
    Even if it's local you can still try rsync, it has an --delete option, to delete files in the target that you've deleted in the source directory.

      Thanks for your reply ,

      but could you give me a link about that ?? (Explaintion)

        Are you on *NIX?

        man rsync is a great source of info!

        cheers

        SK

Re: Incremental Backup
by anonymized user 468275 (Curate) on Aug 25, 2005 at 09:16 UTC
    IMO, the short answer is - you don't want to do it like that.

    Incremental backup means that only files which are new or modified since the previous backup will be included in the backup.

    Incremental backup needs reference full backups in case a full system restore is needed. These are usually weekly to avoid too many increments to restore and some kind of historical archiving is a good idea.

    Backup should take place when the system is disabled from users to avoid the kind of synchronisation issues you are talking about.

    If the system has to be up all the time, the best trick is to use shadow-recorded volumes which can be taken out of normal use so that backup can occur in single user mode on a per-volume basis and still occur in parallel with multi-user operability. When backed up, the shadow volume can be brought back into service as a shadow of the new state of its master volume. The idea of a directory containing files is itself not the right format for this type of backup - a tar file, which can be zipped and archived off, is more like it.

    As far as I can see, there is no reliable alternative that involves folder synchronisation in the way you describe it, because any files modified on the volume being backed up will acquire an unknown backup status (you lose whether they were backed up before or after creation/modification) - a post-hoc synchronisation run only adds an extra quickie layer of the same problem and removes you even further from where you want to be. Morevoer, the delete you are talking about, can more safely be just left as it is, if you are doing the backup according to the definition above, because the file won't appear in the next increment nor in the next full backup.

    One world, one people

Re: Incremental Backup
by ww (Archbishop) on Aug 25, 2005 at 12:32 UTC
    And are you truly willing to delete all backup files whose originals may have been deleted by some other user (of course, me and thee would never inadvertently delete something vital just before a backup, but other users? )? Murphy's law obtains. oops, I guess that even applies to me and thee.

    Your description and the uses of rsync mentioned by others do what you asked, but unless you have some master backup, or grandparent backup intact, you're begging for grief.

Re: Incremental Backup
by da_kow (Novice) on Aug 25, 2005 at 17:31 UTC
Re: Incremental Backup
by astroboy (Chaplain) on Aug 26, 2005 at 00:43 UTC
    Snapback2 is available from cpan. I use it all the time - it's easy to set up, but very flexible