Skip to content

Instantly share code, notes, and snippets.

@davidlandry93
Created March 12, 2017 17:29
Show Gist options
  • Save davidlandry93/b2a5d6fa72be3b0f8da12014994df4eb to your computer and use it in GitHub Desktop.
Save davidlandry93/b2a5d6fa72be3b0f8da12014994df4eb to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
REMOTE=ovh:/opt/mscs/worlds/
N_TO_KEEP=60
echo "Fetching server data into a temporary folder"
rsync -av ovh:/opt/mscs/worlds/ tmp-backup/
echo "Compressing server fetched data"
tar -cJvf `date +'%Y-%m-%H-%M-%S'`.tar.xz tmp-backup
echo "Deleting temporary folder"
rm -r tmp-backup
echo "Deleting any file other than the ${N_TO_KEEP} most recent"
ls -tp | grep -v '/$' | tail -n +$((N_TO_KEEP + 1)) | xargs -I {} rm -- {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment