Skip to content

Instantly share code, notes, and snippets.

@wouterds
Last active December 29, 2015 22:09
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 wouterds/7734948 to your computer and use it in GitHub Desktop.
Save wouterds/7734948 to your computer and use it in GitHub Desktop.
VPS backup script to remote
#!/bin/sh
## System Setup
## backup directory for temporary file storage
BACKUP=/backups
## FTP
FTP_DIR="/path/to/your/backup/folder/"
FTP_USER="your-ftp-username"
FTP_PASS="your-ftp-password"
FTP_HOST="ftp.yourhost.com"
FTP_PORT="21"
## Binaries
TAR="$(which tar)"
FTP="$(which ftp)"
## Today + hour in 24h format
NOW=$(date +%Y%m%d)
## To backup
DUMPFILE=$NOW.tar.bz2
$TAR -cjf $BACKUP/$DUMPFILE /home /srv /etc /var /root
## ftp
cd $BACKUP
$FTP -in $FTP_HOST $FTP_PORT <<END_SCRIPT
quote USER $FTP_USER
quote PASS $FTP_PASS
cd $FTP_DIR
mput $DUMPFILE
bye
END_SCRIPT
## deleting temp files
rm -rf $DUMPFILE
echo "Backup finished and transferred"
exit
@wouterds
Copy link
Author

Better way of backing up, but slower and more intensive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment