/var/net/sys/admin/blog
| More

INTRODUCTION

Data backup is the process of making copies of data in order to protect and restore original files whenever data loss happens. Aside from automated routine data backup, this method does not protect against failure and natural disasters. This is where off-site data backup comes in.

OBJECTIVE

To establish an off-site backup of important data such as website and configuration files, and database, by copying and burning it to a removable media via DVD.

Sample Scenario:

We need to backup the webserver files and database, and burn it on DVD disc.

PRE-BACKUP PROCEDURES:

1.    Website Files
important directories:
/var/www
/etc/httpd

Assuming you have weekly backup @ FLTWWW01, we can just copy that file in format:
FLTWWW01.freelinuxtutorials.com-var-www-html.yyyymmdd.tar.gz
FLTWWW01.freelinuxtutorials.com-etc-httpd.yyyymmdd.tar.gz

2.    Database

For a consistent copy of database backup, read lock should be implemented on the database. Fortunately, we can do it on the slave database server without interrupting the MySQL service.

Write a script sqlbackup.sh that will be run on FLTVMM1-DBSERVER to stop the slave,read lock and dump the database to a certain location.
—————————————————-
#!/bin/sh
date=`/bin/date +%Y%m%d-%H`

/usr/bin/mysqladmin –user=root –password=password stop-slave
/usr/bin/mysqldump –user=root –password=password –lock-all-tables –all-databases > /storage/temp/backup-${date}.sql
/usr/bin/mysqladmin –user=root –password=password start-slave
/bin/tar zcvf backup-${date}.sql.tar.gz backup-${date}.sql

—————————————————–

BACKUP PROCESS:

Backup Data on DVD

1. First install the package dvd+rw-tools
#yum install dvd+rw-tools

2. check if dvd drive is present by displaying the information about disk drive
dvd+rw-mediainfo /dev/dvd

3. Create the ISO image
e.g.
# mkisofs -r -o /tmp/var-www-disk1.iso /var/www

Website Files: (1st DVD)
@FLTVMM1   → /storage/lun1/BACKUP/www/application

#cd /storage/lun1/BACKUP/www/temp
#mkisofs -r -o wwwprod.iso /storage/lun1/BACKUP/www/application/FLTWWW01.freelinuxtutorials.com-var-www-html.yyyymmdd.tar.gz
/storage/lun1/BACKUP/www/applicaiton/FLTWWW01.freelinuxtutorials.com-etc-httpd.yyyymmdd.tar.gz

Database: (2nd DVD)
@FLTVMM1-DBSERVER

#cd /storage/temp
#./sqlbackup.sh (can be scheduled automatically, hours before offsite backup)
#mkisofs -r -o database.iso /storage/temp/backup-yyyymmdd-hh.tar.gz

4. Write the ISO onto the DVD
Website Files:
# growisofs -Z /dev/dvd=/storage/lun1/BACKUP/www/temp/wwwprod.iso

Database:
# growisofs -Z /dev/dvd=/storage/temp/database.iso

5. To append more data for same DVD [Optional]
# growisofs -M /dev/dvd /tmp/file1

VERIFICATION:

1. To verify if data was burned successfully, insert the DVD on the drive and mount it

#mkdir /mnt/dvd
#mount -t iso9660 -o ro /dev/dvd /mnt/dvd

2. List the files and archive
#ls -lah /mnt/dvd
#tar -tf  file.tar.gz

RESTORATION PROCEDURE:

Website Files:
1.    Create the mount directory if not exists
#mkdir /mnt/dvd
2.    Mount the DVD
#mount -t auto /dev/dvd /mnt/dvd
3.    Decompress the files in a particular directory
#cd /tmp
#tar zxvf FLTWWW01.freelinuxtutorials.com-var-www-html.yyyymmdd.tar.gz
#tar zxvf FLTWWW01.freelinuxtutorials.com-etc-httpd.yyyymmdd.tar.gz
4. Select the files/folder that you need and copy to a specific directory

Database:
1. Create the mount directory if not exists
#mkdir /mnt/dvd
2. Mount the DVD
#mount -t auto /dev/dvd /mnt/dvd
3.    Decompress the  sql file in a particular directory
#cd /tmp
#tar zxvf backup-yyyymmdd-hh.tar.gz
4.    A .sql file will be decompress
5.    Restore a specific database using the mysql command
#mysql -u root -p databasename < backup-yyyymmdd-hh.sql

Share

Leave a comment

Name: (Required)

E-mail: (Required)

Website:

Comment:

 

About FLT

This site is dedicated to everyone who likes to learn and explore the beautiful world of Linux. If you have comments and suggestions, please feel free to email at freelinuxtutorials@gmail.com. I am happy to serve and share things esp. that is free and enjoyable as Linux.