Skip to content

Instantly share code, notes, and snippets.

@evandonovan
Last active May 25, 2016 15:13
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 evandonovan/0387d427d9d9dcbf7d2977f90a2e26a9 to your computer and use it in GitHub Desktop.
Save evandonovan/0387d427d9d9dcbf7d2977f90a2e26a9 to your computer and use it in GitHub Desktop.
#! /bin/bash
# set user
USER="usr"
# set port
PORT="22"
# set remote IP (put yours here)
HOST="127.0.0.1"
# set src directory
SRC="/src/dir/here"
# set backup directory
DST="/backup/dir/here"
# set name of database to test
DBNAME="db_test"
# get yesterday's date (Daylight Savings Time-safe)
PREVDAY=$(date -d "yesterday 13:00 " '+%Y%m%d')
# get today's date
TODAY=$(date '+%Y%m%d')
# copy the files over
# this requires the sshpass utility to do the transfer
# (put in the password for your remote server where it says "password"
sshpass -p 'password' scp -P $PORT $USER@$HOST:$SRC/*.sql $DST
# delete all the old backups if backups exist from today now
if [ -f "$DST/$DBNAME.$TODAY.sql" ]
then rm -rf $DST/*.$PREVDAY.sql
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment