Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/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

Simple FTP based backup of a zip file

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment