Jan
22
2010
In the last days i lost some (non critical) data cause i had forgot to install rsnapshot in my laptop. I was without network for a couple of hours and there was nothing on TV. So … i’ve played with bash and made a bash script to backup some directories with a snapshot logic.
The bash script is really simple and straight-forward without any difficult parts. So you can easily configure it, to serve your needs.
#!/bin/bash
# Evaggelos Balaskas, <ebalaskas AT ebalaskas DOT gr>, 20090122
DIR="/var/cache/pacman/pkglist"
PATHS="/etc /usr/local/etc /boot"
BACKUP="backup"
PACMAN="/usr/bin/pacman -Qqe"
RSYNC="/usr/bin/rsync -ra"
MKDIR="/bin/mkdir -p"
DATE="/bin/date"
CP="/bin/cp -al "
MV="/bin/mv -f"
RM="/bin/rm -rf"
TOUCH="/bin/touch"
DAYS="10"
# Make Directory Structure
$MKDIR $DIR/`$DATE +%Y/%m/%d`
#Package List
$PACMAN > $DIR/`$DATE +%Y/%m/%d/pkglist_%H_%M`
#Rotation
if [ -d "$DIR/$BACKUP.$DAYS" ] ; then
$RM $DIR/$BACKUP.$DAYS
fi
for i in `seq $(expr $DAYS - 1 ) -1 1` ;do
if [ -d "$DIR/$BACKUP.$i" ]; then
$MV $DIR/$BACKUP.$i $DIR/$BACKUP.$(expr $i + 1)
fi
done
# Create Hard Link
if [ -d "$DIR/$BACKUP.0" ] ; then
$CP $DIR/$BACKUP.0 $DIR/$BACKUP.1
fi
# Sychronization
for k in $PATHS; do
$MKDIR $DIR/$BACKUP.0$k/
$RSYNC --delete $k/ $DIR/$BACKUP.0$k
done
# TimeStamp
$TOUCH $DIR/$BACKUP.0
Thursday, January 28, 2010 - 18:09:15
Cool script. Added it to my library:
http://fosslib.tsakf.net/record/341