Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Backup foundrydata folder
#!/bin/bash
FOUNDRYDATA="/home/jelastic/foundrydata"
DESTINATION="/home/jelastic/backups/"
BACKUPS_TO_KEEP=5
TIME_FORMAT=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
slow() {
start=`date +%s`
tar -cvJf "$DESTINATION/foundrydata-$TIME_FORMAT.tar.xz" $FOUNDRYDATA
end=`date +%s`
echo Backup took `expr $end - $start` seconds.
}
fast() {
start=`date +%s`
tar -cvzf "$DESTINATION/foundrydata-$TIME_FORMAT.tar.gz" $FOUNDRYDATA
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