backup/backup.sh
2019-06-04 21:39:41 +01:00

36 lines
787 B
Bash

#!/bin/bash
if [ `whoami` != 'root' ] ; then
echo "Permission Denied"
exit
fi
src=/
dst=/media/tom/d533e3a2-c332-40e6-82a9-9a22f2dded45/Backup
args=(
--exclude /sys
--exclude /proc
--exclude /dev
--exclude /media
--exclude /mnt
--exclude /var/cache/apt/archives
--exclude '/home/*/.cache'
--exclude '/home/*/.local/share/Trash/'
--exclude '/home/*/Downloads'
--exclude /storage
)
# do a backup
touch $dst/next.log
tail -n0 --pid="$$" -f $dst/next.log &
rsync "${args[@]}" -av --link-dest=$dst/current $src/ $dst/next 2>&1 >> $dst/next.log || exit
# success, clean up
date=`date "+%Y-%m-%dT%H:%M:%S"`
mv $dst/next $dst/$date
mv $dst/next.log $dst/$date.log
unlink $dst/current
unlink $dst/current.log
ln -s $dst/$date $dst/current
ln -s $dst/$date.log $dst/current.log