Last active
January 4, 2016 20:29
-
-
Save xr09/8674546 to your computer and use it in GitHub Desktop.
Minimal rotating backup system
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
#!/usr/bin/bash | |
backup_number=8 | |
base_name="backup.gz" | |
backup_path="/opt/somebackup/" | |
cd $backup_path | |
# clean any old temp backup | |
rm -f *.tmp | |
# change this line with your specific backup: pgdump, tar, rsync, etc.. | |
echo "$(date +%T)" > "$base_name".tmp | |
# make sure the backups are getting done before discarding old ones | |
if [ ! -f "$base_name".tmp ] | |
then | |
echo "ERROR: Backup file \"$base_name.tmp\" not found" | |
exit -1 | |
fi | |
# delete the oldest | |
rm -f $base_name.$backup_number | |
# rotate backups | |
for i in $(seq $backup_number -1 2) | |
do | |
if [ -f "$base_name".$(($i-1)) ] | |
then | |
mv "$base_name".$(($i-1)) "$base_name".$i | |
fi | |
done | |
# tmp is now the newest backup | |
mv "$base_name".tmp "$base_name".1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could use a
set -e
?