💾 Archived View for republic.circumlunar.space › users › andybalaam › blogmirror › 2007-02-23_my_dai… captured on 2023-11-14 at 08:12:02. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-04)

-=-=-=-=-=-=-

My daily backup

I recently recovered my files from my daily backup, which had actually worked!

(Pop quiz: this is how I deleted half my home dir - what is wrong with this Makefile?

TMP_DIR=/tmp/gssmp

blah: blah1
   blah

...

blah7:
   ...
   rm -rf $TMPDIR/

...

)

Anyway, I am extremely grateful that the backup did work, but a slight problem was that I have been backing up absolutely everything, and never deleting anything that was backed up until I ran out of disk space.

So when I restored from backup, every file I had ever deleted (since I started backing up) re-appeared. This included files and dirs (and email) that had just been moved somewhere else - I now had 2 copies of them.

I've spent the night deleting stuff that I didn't actually want restored, and this has encouraged me to create an improved backup script that puts deleted stuff into a separate folder, named after the day it was deleted. I can delete those folders at my leisure when they get too big, but when a disaster happens like it did on Wednesday, I can restore back to a sane state by just ignoring any irrelevant deleted folders.

It's quite simple, but I hadn't thought of it before, so it might be helpful to others. Enjoy:

#!/bin/bash

# Copy this to /etc/cron.daily and make it owned by root, and executable

# Back up everything important from my main drive (hda) to the backup
# drive (hdb).

# Keep stuff that has been deleted from the real drive in a separate
# backup dir, named after the day it was deleted.

BKP_DRIVE=/media/hdb1

FLAGS="-a --delete-during --max-delete 100 --backup"

DT=`date +%F`
DELETED_DIR=deleted-$DT

function run_rsync
{
   THIS_DIR=$1
   EXCLUDES=$2

   echo rsync $FLAGS --backup-dir=$BKP_DRIVE/$DELETED_DIR$THIS_DIR \
       $EXCLUDES $THIS_DIR/ $BKP_DRIVE$THIS_DIR/
   rsync $FLAGS --backup-dir=$BKP_DRIVE/$DELETED_DIR$THIS_DIR \
       $EXCLUDES $THIS_DIR/ $BKP_DRIVE$THIS_DIR/
}

run_rsync /home/andy \
   "--exclude /iRiver --exclude /downloads --exclude /.Trash --exclude /misc/qemu"

run_rsync /etc

run_rsync /var

run_rsync /boot

Originally posted at 2007-02-23 06:26:37+00:00. Automatically generated from the original post : apologies for the errors introduced.

original post