This script creates a zipfile and uploads it to an FTP server. You can define how many backups should be stored on the server. Older files will be deleted.
Created
April 30, 2017 19:28
-
-
Save kekru/60e0d167fc71cb52c5362fc0168f6c6e to your computer and use it in GitHub Desktop.
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 | |
#Define FTP USername and Pasword | |
USERPW="username:secret" | |
#Define FTP Server | |
SERVER=ftp-server.org | |
#Define how many files you want to keep | |
KEEPFILES=10 | |
#Create zipfile with the contents you want to backup | |
zip -r /data/backup/backup.zip /data/svn/data | |
#Upload the zipfile with a timestamp in its name | |
DATE=`date +%Y-%m-%d_%H-%M-%S` | |
curl -T /data/backup/backup.zip ftp://$SERVER/backup-$DATE.zip --user $USERPW | |
#Delete old backup files | |
#List all files from server | sort the names alphabetically | select all but the last x of them (the last are the newer files) | delete the selected files | |
curl -l ftp://$SERVER/ --user $USERPW | sort | head -n -$KEEPFILES | while read line ; do | |
curl ftp://$SERVER/ -Q "DELE $line" --user $USERPW | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment