Last active
December 18, 2023 04:52
-
-
Save TaylorJadin/d55161f79cbe7726cf04e1b1b3e9d24f to your computer and use it in GitHub Desktop.
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 | |
TARGET="/root/foundry" | |
DESTINATION="/root/backups" | |
BACKUPS_TO_KEEP=20 | |
NOW=`date -u +"%Y-%m-%dT%H:%M:%SZ"` | |
slow() { | |
start=`date +%s` | |
tar -cvJf "$DESTINATION/$NOW.tar.xz" $TARGET | |
end=`date +%s` | |
echo Backup took `expr $end - $start` seconds. | |
} | |
fast() { | |
start=`date +%s` | |
tar -cvzf "$DESTINATION/$NOW.tar.gz" $TARGET | |
end=`date +%s` | |
echo Backup took `expr $end - $start` seconds. | |
} | |
cleanup() { | |
N=$(($BACKUPS_TO_KEEP + 1)) | |
(cd $DESTINATION && ls -tp | grep -v '/$' | tail -n +$N | xargs -I {} rm -- {}) | |
} | |
### Main ### | |
if [ "$1" = "" ]; then | |
fast | |
cleanup | |
else | |
while [ "$1" != "" ]; do | |
case $1 in | |
-s | --slow ) shift | |
slow | |
;; | |
-f | --fast ) fast | |
;; | |
-c | --cleanup ) cleanup | |
;; | |
* ) echo "invalid flag: $1" | |
exit 1 | |
esac | |
shift | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment