Tape backup on CentOS

On this occasion, we have a PHP/Firebird application. We had to backup the database and the code (which includes PHP, HTML, CSS, Javascript files as well as user documents uploaded into a folder).

We have created a folder /mybackup/ and created a bash script backup.sh to do the following, using nano command line editor. We will always have 2 compressed gz files, remove the old ones. Backup the database, compress it. Backup the code folder, compress it. Rewind the tape. Then, copy into the tape. We are expecting the client to eject the tape and insert another one everyday, Monday to Friday.

#!/bin/bash
rm -f *.gz
/opt/firebird/bin/gbak -t -user sysdba -password "mypassword" localhost:mydb /mybackup/mydb.fbk
gzip mydb.fbk
tar -cpf mycode.tar /var/www/html
gzip mycode.tar
mt -f /dev/st0 rewind
tar -cpf /dev/st0 *.gz

(mydb is an alias pointing to a FDB database file defined in Firebird aliases.conf)

Using Webmin, my favourite online system administration tool for Linux, I’ve created a cron job to run /mybackup/backup.sh at required intervals.

Make sure that the user account that runs the commands has the execute and write permissions where needed.

Install mt, if your system has not got it already.

CentOS package manager
CentOS package manager

Leave a Reply