Skip to content

Instantly share code, notes, and snippets.

@bmarini
Created January 4, 2009 20:51
Show Gist options
  • Save bmarini/43178 to your computer and use it in GitHub Desktop.
Save bmarini/43178 to your computer and use it in GitHub Desktop.
A quick and dirty website backup script
#!/bin/bash
# a quick and dirty backup script.
# if you have a websites folder and some databases to backup
# this script might be a good starting point.
# this script assumes you have user named admin.
BASE_DIR='/'
TARGET_DIR='sites'
BACKUP_TIME=`date +%Y%m%d%H%I%S`
BACKUP_FILENAME="${BACKUP_TIME}-${TARGET_DIR}"
BACKUP_DIR='/home/admin/backups'
# Backup the folder
echo "Backing up $TARGET_DIR folder ..."
tar zcf ${BACKUP_DIR}/${BACKUP_FILENAME}.tar.gz -C $BASE_DIR $TARGET_DIR
# Backup the databases, replace database{1,2} with real databases
echo "Backing up the databases ..."
mysqldump database1 | gzip -c ${BACKUP_DIR}/${BACKUP_TIME}-database1.sql.gz
mysqldump database2 | gzip -c ${BACKUP_DIR}/${BACKUP_TIME}-database2.sql.gz
chown -R admin:admin $BACKUP_DIR
echo "Done!"
@alias-mac
Copy link

You have a typo on your BACKUP_TIME. You have hours twice date +%Y%m%d%H%I%S.
I think what you want is date +%Y%m%d%H%M%S.

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