Backup script to FTP with timed subfolders
Posted
by
Frederik Nielsen
on Server Fault
See other posts from Server Fault
or by Frederik Nielsen
Published on 2012-10-07T11:09:58Z
Indexed on
2012/10/07
21:40 UTC
Read the original article
Hit count: 291
I want to make a backup script, that makes a .tar.gz
of a folder I define, say fx /root/tekkit/world
This .tar.gz
file should then be uploaded to a FTP server, named by the time it was uploaded, for example: 07-10-2012-13-00.tar.gz
How should such backup script be written?
I already figured out the .tar.gz
part - just need the naming and the uploading to FTP.
I know that FTP is not the most secure way to do it, but as it is non-sensitive data, and FTP is the only option I have, it will do.
Edit:
I ended up with this script:
#!/bin/bash
# have some path predefined for backup unless one is provided as first argument
BACKUP_DIR="/root/tekkit/world/"
TMP_DIR="/tmp/tekkitbackup/"
FINISH_DIR="/tmp/tekkitfinished/"
# construct name for our archive
TIME=$(date +%d-%m-%Y-%H-%M)
if [ $1 ]; then
BACKUP_DIR="$1"
fi
echo "Backing up dir ... $BACKUP_DIR"
mkdir $TMP_DIR
cp -R $BACKUP_DIR $TMP_DIR
cd $FINISH_DIR
tar czvfp tekkit-$TIME.tar.gz -C $TMP_DIR .
# create upload script for lftp
cat <<EOF> lftp.upload.script
open server
user user password
lcd $FINISH_DIR
mput tekkit-$TIME.tar.gz
exit
EOF
# start backup using lftp and script we created; if all went well print simple message and clean up
lftp -f lftp.upload.script && ( echo Upload successfull ; rm lftp.upload.script )
© Server Fault or respective owner