Skip to content

Instantly share code, notes, and snippets.

@kekru
Created April 30, 2017 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kekru/60e0d167fc71cb52c5362fc0168f6c6e to your computer and use it in GitHub Desktop.
Save kekru/60e0d167fc71cb52c5362fc0168f6c6e to your computer and use it in GitHub Desktop.
#!/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