Created
January 24, 2013 12:58
-
-
Save RodrigoPrior/4621272 to your computer and use it in GitHub Desktop.
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/sh | |
## | |
# basic script to backup entire drive and backup securely | |
# backup a mysql database using lvm snapshot tool | |
## | |
# stop mysql | |
/usr/sbin/service mysql stop | |
# lvm snapshot backup | |
/sbin/lvcreate -L1G -s -n rootsnapshot /dev/server/root | |
# restart mysql | |
/usr/sbin/service mysql start | |
# mount drives | |
mount /dev/server/rootsnapshot /mnt | |
mount /dev/mapper/server-backups /backups | |
# rotate backup (last 2 days) | |
find /backups/ -type f -ctime +1 -exec rm -f '{}' \; | |
# create backup | |
tar -pczf /backups/`date +"%Y%m%d"`_root.tar.gz /mnt | |
# umount drives | |
umount /mnt | |
umount /backups | |
# remove snapshot | |
/sbin/lvremove -f /dev/server/rootsnapshot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment