Hits :
4255
ABS4SNAP
abs4snap stands for: Another Bash Script For Snapshots
For: rpm-based distros
#!/bin/bash
# Evaggelos Balaskas, <ebalaskas AT ebalaskas DOT gr>, 20101126
DIR="/backup/bak"
PATHS="/etc /usr/local/etc /boot /root /var/spool/cron"
BACKUP="backup"
PACMAN="/bin/rpm -qa"
RSYNC="/usr/bin/rsync -ra"
MKDIR="/bin/mkdir -p"
DATE="/bin/date"
CP="/bin/cp -al "
MV="/bin/mv -f"
RM="/bin/rm -rf"
SORT="/bin/sort"
TOUCH="/bin/touch"
DAYS="101"
# Make Directory Structure
$MKDIR $DIR/`$DATE +%Y/%m/%d`
# Package List
$PACMAN | $SORT > $DIR/`$DATE +%Y/%m/%d/pkglist_%H_%M`
# Rotation
if [ -d "$DIR/$BACKUP.$DAYS" ] ; then
$RM $DIR/$BACKUP.$DAYS
fi
# Print zeroes before number. 3 digit, eg 001
function dir_name {
zeroes=""
number=$1
if [ $number -lt 100 ]; then
zeroes="0"
fi
if [ $number -lt 10 ]; then
zeroes="0"$zeroes
fi
echo $zeroes$number
}
# Loop for n Days
for i in `seq $(expr $DAYS – 1 ) -1 1` ;do
CUR_DIR_NAME=$(dir_name $i)
PRE_DIR_NAME=$(dir_name $(expr $i + 1))
# Delete previous/destination folder
if [ -d "$DIR/$BACKUP.$PRE_DIR_NAME" ]; then
$RM $DIR/$BACKUP.$PRE_DIR_NAME
fi
# Move the current folder to previous folder
if [ -d "$DIR/$BACKUP.$CUR_DIR_NAME" ]; then
$MV $DIR/$BACKUP.$CUR_DIR_NAME $DIR/$BACKUP.$PRE_DIR_NAME
fi
done
# Create Hard Link
if [ -d "$DIR/$BACKUP.000" ] ; then
$CP $DIR/$BACKUP.000 $DIR/$BACKUP.001
fi
# Sychronization
for k in $PATHS; do
$MKDIR $DIR/$BACKUP.000$k/
$RSYNC --delete $k/ $DIR/$BACKUP.000$k
done
# TimeStamp
$TOUCH $DIR/$BACKUP.000
top
For Archlinux distro
#!/bin/bash
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="101"
# Make Directory Structure
$MKDIR $DIR/`$DATE +%Y/%m/%d`
# Package List
$PACMAN | $SORT > $DIR/`$DATE +%Y/%m/%d/pkglist_%H_%M`
# Rotation
if [ -d "$DIR/$BACKUP.$DAYS" ] ; then
$RM $DIR/$BACKUP.$DAYS
fi
# Print zeroes before number. 3 digit, eg 001
function dir_name {
zeroes=""
number=$1
if [ $number -lt 100 ]; then
zeroes="0"
fi
if [ $number -lt 10 ]; then
zeroes="0"$zeroes
fi
echo $zeroes$number
}
# Loop for n Days
for i in `seq $(expr $DAYS – 1 ) -1 1` ;do
CUR_DIR_NAME=$(dir_name $i)
PRE_DIR_NAME=$(dir_name $(expr $i + 1))
# Delete previous/destination folder
if [ -d "$DIR/$BACKUP.$PRE_DIR_NAME" ]; then
$RM $DIR/$BACKUP.$PRE_DIR_NAME
fi
# Move the current folder to previous folder
if [ -d "$DIR/$BACKUP.$CUR_DIR_NAME" ]; then
$MV $DIR/$BACKUP.$CUR_DIR_NAME $DIR/$BACKUP.$PRE_DIR_NAME
fi
done
# Create Hard Link
if [ -d "$DIR/$BACKUP.000" ] ; then
$CP $DIR/$BACKUP.000 $DIR/$BACKUP.001
fi
# Sychronization
for k in $PATHS; do
$MKDIR $DIR/$BACKUP.000$k/
$RSYNC --delete $k/ $DIR/$BACKUP.000$k
done
# TimeStamp
$TOUCH $DIR/$BACKUP.000
top