Last active
September 24, 2020 11:32
-
-
Save antonshell/6ee1bb1ca19d98d91a1bbcbb5cf55afa to your computer and use it in GitHub Desktop.
Backup files to external server via SFTP
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 | |
TIMESTAMP=$(date +"%F-%T") | |
FILES_DIR=/var/www/my_website/web/uploads | |
BACKUP_DIR="/var/backups/files/my_website_backups/$TIMESTAMP" | |
TAR=/usr/bin/tar | |
REMOTE_HOST="192.168.1.55" | |
REMOTE_USER="backup" | |
REMOTE_PASSWORD="password" | |
REMOTE_DIR=/home/backup/files_backups/ | |
REMOTE_PORT="22" | |
SSHPASS=/usr/bin/sshpass | |
RSYNC=/usr/bin/rsync | |
mkdir -p "$BACKUP_DIR" | |
$TAR -zcvf $BACKUP_DIR/files.tar.gz $FILES_DIR | |
$SSHPASS -p $REMOTE_PASSWORD $RSYNC -r -e "ssh -p $REMOTE_PORT" $BACKUP_DIR $REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR | |
rm -rf "$BACKUP_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment