Skip to content

Instantly share code, notes, and snippets.

@alexclifford
Created August 5, 2014 10:32
Show Gist options
  • Save alexclifford/54bc6c565fca233faca4 to your computer and use it in GitHub Desktop.
Save alexclifford/54bc6c565fca233faca4 to your computer and use it in GitHub Desktop.
Quickly backup a bunch of directories on centos server
#!/bin/bash
BACKUP_PATH="/root/backups/"
BACKUP_DIR=$BACKUP_PATH$(date +%F)"/"
TARGETS="/root/.bash_history /root/.bashrc /root/.ssh /root/.subversion /etc/httpd/conf /etc/httpd/conf.d /var/www /etc/ssh/sshd_config"
# Loop through $TARGETS and rsync them all to $BACKUP_DIR but maintaining their directory paths
for DIR in `echo $TARGETS`
do
mkdir -p $BACKUP_DIR$(dirname ${DIR})
rsync -av $DIR $BACKUP_DIR$(dirname ${DIR})
done
tar -czf $BACKUP_PATH$(date +%F).tar.gz $BACKUP_DIR
rm -rf $BACKUP_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment