I want to make a backup script, that makes a
.tar.gz of a folder I define, say fx
.tar.gz file should then be uploaded to a FTP server, named by the time it was uploaded, for example:
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.
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 )