This is a very primitive and bad script. I've posted a new version here.
"No backup no pity!"
I don't agree. But I like the saying for reasons that I shall not analyse here right now.
I don't always have proper backups of my data, let alone off-site backups. I have no backup at all of a large portion of my hoarded data. But I did at some point take the time to create scripts that back up important stuff automatically. Here is a simple one using rsync and a mounted share as a target.
#!/bin/bash
NAME="usershomedir"
SRCDIR="/home/user"
BUDIR="/mnt/backup/"
rm -rf $BUDIR$NAME.8
mv $BUDIR$NAME.7 $BUDIR$NAME.8
mv $BUDIR$NAME.6 $BUDIR$NAME.7
mv $BUDIR$NAME.5 $BUDIR$NAME.6
mv $BUDIR$NAME.4 $BUDIR$NAME.5
mv $BUDIR$NAME.3 $BUDIR$NAME.4
mv $BUDIR$NAME.2 $BUDIR$NAME.3
mv $BUDIR$NAME.1 $BUDIR$NAME.2
cp -al $BUDIR$NAME.0 $BUDIR$NAME.1
NOW=$(date)
echo >> $BUDIR$NAME.log
echo >> $BUDIR$NAME.log
echo >> $BUDIR$NAME.log
echo "##### STARTING INCREMENTAL BACKUP AT $NOW" >> $BUDIR$NAME.log
echo >> $BUDIR$NAME.log
rsync --archive -L --delete $SRCDIR $BUDIR$NAME.0/ 2>&1 | tee -a $BUDIR$NAME.log
You would create one of these scripts per directory you want to backup. BUDIR
is the directory where you want to backup to be stored. This will probably be the same for every script if you have only one backup drive/server. SRCDIR
is the directory you want to backup. NAME
is the name you want the backup to be stored under. It can be a sub-directory if you want, so you can sort the backups into directories on the target.