Skip to content

Instantly share code, notes, and snippets.

@temperatio
Created March 16, 2018 08:44
Show Gist options
  • Save temperatio/371f7e6f1c5de69f2b1031b31f0739f1 to your computer and use it in GitHub Desktop.
Save temperatio/371f7e6f1c5de69f2b1031b31f0739f1 to your computer and use it in GitHub Desktop.
Backup a given path and upload to remote server
#!/bin/sh
# Create a db dump and upload it to another server
#
BACK_SERVER='xxx.xxx.xxx.xxx'
BACK_SERVER_PORT='22'
BACK_SERVER_USER='user'
# store current date
NOW=`date +%Y.%m.%d.%H:%M`
YEAR=`date +%Y`
MONTH=`date +%m`
DAY=`date +%d`
# Working paths
HTML_PATH="/path/to/backup/"
EXCLUDE_PATH="/path/to/backup/excludepath"
TMP_PATH="/tmp/filebackup-$NOW"
BZ_BACKUP="$TMP_PATH/html.$NOW.tar.bz2"
REMOTE_PATH="~/backups/$YEAR/$MONTH"
mkdir $TMP_PATH
tar jcvf $BZ_BACKUP $HTML_PATH --exclude=$EXCLUDE_PATH
ssh -p $BACK_SERVER_PORT $BACK_SERVER_USER@$BACK_SERVER mkdir -p $REMOTE_PATH
scp -P $BACK_SERVER_PORT $BZ_BACKUP $BACK_SERVER_USER@$BACK_SERVER:$REMOTE_PATH
rm -rf $TMP_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment