Last active
February 16, 2018 00:33
-
-
Save mcrmonkey/c3504ad65ee9ce22244d81b02d327f7b to your computer and use it in GitHub Desktop.
quick-n-dirty regular backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Doesn't copy already existing files if they are in the previous backup | |
## First do echo "initial" > LASTBACKUP.dat then mkdir Backup-initial && cd Backup-initial && rsync -a --progress /source/path . && cd .. | |
DATE=`date +"%Y%m%d"` | |
LASTD=`cat LASTBACKUP.dat` | |
echo -ne "\n\nBackup script\n =========" | |
echo -ne "\n\nBacking up to: Backup-$DATE\n" | |
echo -ne "Previous Backup: Backup-$LASTD\n\n" | |
if [ ! -d "Backup-$LASTD" ]; then | |
echo "ERROR: Last backup not there" | |
exit 1 | |
fi | |
sleep 3 | |
if [ ! -d "Backup-$DATE" ]; then | |
mkdir Backup-$DATE | |
fi | |
cd Backup-$DATE | |
rsync -rtlDP --exclude=.cache /source/path --link-dest=../Backup-$LASTD . | |
if [ "$?" -eq 0 ]; then | |
echo "Backup success!" | |
echo -ne "\n\n Ctrl-C to stop LASTBACKUP.dat update\n\n" | |
sleep 20 | |
cd .. | |
echo "$DATE" > LASTBACKUP.dat | |
rm ./current | |
ln -s ./Backup-$DATE current | |
else | |
echo "nope" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment