Weblog entry #8 for pedxing

Automated backups to GMail
Posted by pedxing on Fri 29 Jul 2005 at 02:23
Tags: none.
I want to back up mysql and a few small files to my gmail account every night.

First, I have a crontab entry run a script to dump the mysql database.
0 0 * * * /root/bin/dumpmysql
the dumpmysql script is one line:
/usr/bin/mysqldump --user=root --password=mysqlpassword --all-databases > /home/jay/backup/`date +%F`-backup.sql

The reason I have crontab call this script is that if I put that line in my crontab, my mysql password will be in my logs, as well as the process list while it's running.

I also create symlinks in /home/jay/backup to any files or folders I want to copy offsite.

I then have another entry in my crontab to use mpack to create a MIME message and send it to my gmail account.
The subject of the message (-s switch) is the date. The body of the message is the output from tar, temporarily held in /tmp/dumpmsg.txt. The contents of the folder are tar/gzipped and attatched.

0 1 * * * tar zvvcf /tmp/dump.tgz /home/jay/backup > /tmp/dumpmsg.txt ; mpack -s `date +%F` -d /tmp/dumpmsg.txt /tmp/dump.tgz jaywstapleton@gmail.com; rm /tmp/dumpmsg.txt; rm /tmp/dump.tgz

The message is formatted like this:

-----
2005-07-28

jay (jay@pedxing.org) to me 8:36 pm (1 hour ago)
drwxr-xr-x jay/jay 0 2005-07-28 20:32:06 /home/jay/backup/
-rw-r--r-- root/root 10524 2005-06-25 09:49:19 /home/jay/backup/testfile
-rw-r--r-- root/root 27910 2005-06-25 21:03:32 /home/jay/backup/2005-06-25-backup.sql
lrwxrwxrwx jay/jay 0 2005-07-28 20:32:06 /home/jay/backup/link.to.a.file -> /home/jay/files/a.file.to.link.to/

dump.tgz
8K Download
-----

Comments

 

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search