Skip to content

Instantly share code, notes, and snippets.

@n3rd
Created April 24, 2019 18:31
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 n3rd/d8723d4cf6ca7e0b00c7dcb4613ae163 to your computer and use it in GitHub Desktop.
Save n3rd/d8723d4cf6ca7e0b00c7dcb4613ae163 to your computer and use it in GitHub Desktop.
Script for scheduled recursive FTP backup
#!/bin/bash
# backups a ftp host (complete all recursive)
# currently does not support the backup of a specified directory
cd "$(dirname "$0")"
backupfile=$(date +%Y%m%d)
savetodir=./backup-$(date +%Y)/
host=ftp.site.com
user=readonlyuser
pass=superseretpassword
if [ -d $host ]; then
rm -r $host
fi
wget --recursive --level=inf --quiet --user=$user --password=$pass ftp://$host/
if [ $? -ne 0 ]; then
echo "wget faild during the backup of $host" >&2
exit 1
fi
tar -cf $backupfile.tar $host && gzip -c $backupfile.tar > $backupfile.tar.gz && rm $backupfile.tar
if [ $? -ne 0 ]; then
echo "faild to create a tar.gz during the backup of $host" >&2
exit 1
fi
if [ ! -d $savetodir ]; then
mkdir $savetodir
fi
mv $backupfile.tar.gz $savetodir
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment