Created
April 24, 2019 18:31
-
-
Save n3rd/d8723d4cf6ca7e0b00c7dcb4613ae163 to your computer and use it in GitHub Desktop.
Script for scheduled recursive FTP backup
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 | |
# 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