Created
January 25, 2013 12:11
-
-
Save blu3Alien/4633972 to your computer and use it in GitHub Desktop.
Shell script to store a compressed backup of vital server files in the users home directory.
Note: Care should be taken when using this. Consider changing the backup location.
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 | |
date=`date -I` | |
log_date=`date -u` | |
# Compress and backup /etc directory | |
tar -cvf ~/backup/etc-$date.tar /etc | |
echo "[$log_date]: Backing up /etc directory. (etc-$date.tar)" >> ~/backup/logs/_backup.txt | |
# Compress and backup /home directory | |
tar -cvzf ~/backup/home-$date.tar /home | |
echo "[$log_date]: Backing up /home directory. (home-$date.tar)" >> ~/backup/logs/_backup.txt | |
# Compress and backup /srv directory | |
tar -cvzf ~/backup/srv-$date.tar /srv | |
echo "[$log_date]: Backing up /srv directory. (srv-$date.tar)" >> ~/backup/logs/_backup.txt | |
# Remove backups older than 3 months | |
find ~/backup/ -name "*.tar" -mtime +90 -exec rm {} \; | |
echo "[$log_date]: Removing old monthly backups." >> ~/backup/logs/_backup.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment