Bash backup script

Posted by & filed under Linux, Server.

Here’s a script for backing up directories and databases. All files are compresses, and files older than 30 days are removed.

#
# Backup script
#
# Make compressed backups of directories/files, and old backups

# Format: YEAR MONTH DAY - HOUR MINUTE SECOND
DATE=$(date +%Y%m%d-%H%M%S)

# backup directories and files
tar -czf "/backup/target_file-$DATE.tar.gz" /home/username/public_html/home/
tar -czf "/backup/target_file_forwarders-$DATE.tar.gz" /etc/valiases/domain_name.co.uk

# backup databases
# this could be done in one command, but I want to keep separate files
mysqldump database1 | gzip -f > "/backup/databases/database1-$DATE.sql.gz"
mysqldump database2 | gzip -f > "/backup/databases/database2-$DATE.sql.gz"

# delete files older than 30 days recursively on this path
find /backup -type f -mtime +30 -exec rm -f {} \;

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Bitnami