Are you running a software development project that has a Bugzilla database in MySQL, and a source code repository in Subversion? Do you have secure shell access to another box that you would like to back up both data stores to? Here's how.
First, create a shell script to create a dump of the Bugzilla bugs database. For security purposes, the script uses a username and password of bugs_ro, which stands for "bugs, read-only". The creation of this user is not part of the Bugzilla install, naturally, but it's something you should do: create a user that has read-only access to the Bugzilla database in MySQL. It follows the security principle of least access. Here's the script:
#!/bin/sh # backup_bugs_db.sh --> backs up the bugs db to a dump file cp -f bugs_db_today.mysqldump bugs_db_yesterday.mysqldump # * * * NOTE * * * there can be no space between -p and the password! mysqldump -u bugs_ro -pbugs_ro --add-drop-table bugs > bugs_db_today.mysqldump chmod 644 bugs_db_today.mysqldump
Now, create a shell script that will call the above script, and that will also back up the subversion database. This script can be attached to a cron job that gets run as root. But, notice how some lines in this script are purposefully run as less priveledged users. This script will only work if you have created a Unix user named "backups".
In this example, the backups user has also been created on a server called mybackupserver.com. Furthermore, the backups user has password-free login capabilities to mybackupserver.com. (Here's how to configure password-free login.)
Note how we build up a text file that we pipe through e-mail at the end of the script, as a nice way of letting people who care know that the backups have been made.
#!/bin/sh # create_backups.sh --> backs up Bugzilla's db (known as bugs) # from MySQL; backs up svn repository; ssh's it to mybackupserver.com; # e-mails me and my colleague about it. Intended to be run as a cron # job as root. # Create two files: # /var/lib/mysql/bugs_db_today.mysqldump # /var/lib/mysql/bugs_db_yesterday.mysqldump su - mysql -c /var/lib/mysql/backup_bugs_db.sh # Now make sure the user named backups has these files. cp /var/lib/mysql/bugs_db_today.mysqldump /home/backups cp /var/lib/mysql/bugs_db_yesterday.mysqldump /home/backups # Back up our subversion repository: cp -f /home/backups/svn_today.dump /home/backups/svn_yesterday.dump svnadmin dump --quiet /usr/local/svn_repository > /home/backups/svn_today.dump # Now make sure the user named backups owns these files. chown backups /home/backups/*dump chmod 644 /home/backups/*dump # Secure copy the files to mybackupserver.com su - backups -c "scp -B -q /home/backups/*dump backups@mybackupserver.com:" # Now send an e-mail about our success echo "The following backups were Secure-Copied to mybackupserver.com:" > /root/backups_email.txt ls -l /home/backups/*dump >> /root/backups_email.txt cat /root/backups_email.txt | mail -s "my backups" myself@mycorporation.com mycoleague@mycorporation.com