[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How I keep track of file additions/removals.



Hi,

Just wanted to share this in case it's useful to any other user (or in case
somebody has a better solution to this as well).

I use tarsnap for backing up photos. So, in truth, there are no modifications
to my files, only additions and deletions.  I wanted some way of keeping track
of what I delete/add easily (especially to find *when* I deleted something,
etc).

tarsnap -t -v get some of the work done - but I'd need to do this for every
archive, and I've several thousand files (photos), so it's slow, and
inefficient (and not free!).

So I wrote a tiny backup script that keeps a listing of files inside the backed
up directory right when each backup is done:

    #!/bin/sh

    set -e
    set -u

    FILE_DIR=/home/hugo/photos
    META_DIR=/home/hugo/.local/share/tarsnap/index
    CACHE_DIR=/home/hugo/.local/share/tarsnap/cache
    WHEN=$(date +%Y-%m-%dT%H%M%S%z)
    KEY=/path/to/write/only.key

    # Update the file index.
    find $FILE_DIR | sort > $META_DIR/photos
    git -C $META_DIR add $META_DIR/photos
    git -C $META_DIR commit -m "Update photos index file for $WHEN."

    # Perform the backup itself.
    tarsnap -c --keyfile $KEY --cachedir $CACHE_DIR -f photos-$WHEN \
      --exclude "Unsorted" --one-file-system  --print-stats $FILE_DIR

So now I've a git repository with a file with the listing for the files on each
backup.

Simply running `git log -p photos` inside the repository will show a very
friendly and readable changelog of added and deleted files, sorted
chronologically.

Cheers, and thanks for tarsnap!

-- 
Hugo Osvaldo Barrera
A: Because we read from top to bottom, left to right.
Q: Why should I start my reply below the quoted text?

Attachment: pgpbQ6ig9ZGNE.pgp
Description: PGP signature