Vous êtes sur la page 1sur 6

ITC 355

Server Administration and Maintenance


Assignment 2

Submitted to:
Linh Pham

Submitted by :
Khandaker Islam(11427188)

Backup task/job documentation

The main purpose of the task is taking daily, monthly and


incremental backup from a mysql database and scheduling and

Khandaker Islam(11427188)
ITC 355 Server Administration and Maintenance
Assignment 2 Page 1
automating the process using perl script and crotab. I have
explained step by step below,

Adding new user:

Create user to implement backup and restore system, create 2


users name ‘linus’ & ‘backup’

[root@localhost ~ ]# adduser linus


[root@localhost ~ ]# passwd linus

The main purpose of creating another user is all databases


backup and folder backup task will be done from user account.

Mysql Server Implementation:

If mysql is not installed, put the following command to install


mysql on CentOS which must be done from root account.

[root@localhost ~ ]#yum install mysql

To start mysql daemon, use the following command

[root@localhost ~ ]#/etc/init.d/mysqld start

Or

[root@localhost ~ ]#service mysqld start

After starting type mysql on the prompt to open mysql and create
a new database name itc333db;

Mysql >create database itc333db;

The database is created from root account and need to give


privilege to other uses to get access on it. For an example, I am
giving privilege user ‘linus’ and ‘backup’ on the database using
following command and password is ‘123456’

Khandaker Islam(11427188)
ITC 355 Server Administration and Maintenance
Assignment 2 Page 2
Mysql> grant all privileges on itc333db. * to linus@localhost
identified by ‘123456’;

Mysql> grant all privileges on itc333db. * to backup@localhost


identified by ‘123456’;

[MySQL 5.0 Reference]

Now switch to user ‘linus’ to implement backup

[root@localhost ~ ]#su linus >> to login to linus


[linus@localhost ~ ]#

Backup implementation and script

We will run a perl script to take backup every certain time we will
configure. Now login to database using created user name and
password.

[linus@localhost ~]$ mysql -u linus -p123456

To take a backup we can run the following command,

[linus@localhost ~ ]#mysqldump itc333db –u linus –p123456 >


itc333backup.db;

Scheduling and Automating Backup

We are going to take backup Monday to Friday and 10pm in the


evening after.

So we have to run crontab to implement the schedule the backup.


To run crontab editor run

[linus@localhost ~]$ crontab –e

And put the following conditions to implement the daily and


monthly schedule .

Khandaker Islam(11427188)
ITC 355 Server Administration and Maintenance
Assignment 2 Page 3
1. Week days(Monday-Friday) at 10:00PM

30 22 * * 1-5 /home/linus/dbscript.pl

2. End of the month 10:00PM the script will take monthly


backup

0 22 28-31 * * /home/linus/mbscript.pl

[crontab & cronjob]

We are running monthly backup for last 4 days of the month


because month could be 28 or 30 or 31. End of the month the
script will take complete backup.

0 22 28-31 * * /home/linus/mbscript.pl

[crontab & cronjob]

Perl Script to run backup

We are running 2 scripts to run daily backup and monthly backup


and copy the file to backup folder

Dbscript.pl is the file for daily backup

#!/usr/bin/perl

$val = `date +%d%m%y%H%M`;

`mysqldump itc333 -u linus -p123456 > itc333.sql.$val`;

`cp -R /home/linus/ /home/backup/linus.$val`;

[Writing perl script]

Mbscript.pl script for monthly backup

#!/usr/bin/perl

$m = `date +%b%Y`;
Khandaker Islam(11427188)
ITC 355 Server Administration and Maintenance
Assignment 2 Page 4
`mysqldump itc333 -u linus -p123456 > itc333.sql.$m `;

`cp -R /home/linus/ /home/backup/linus.$val`;

[Writing perl script]

References

Khandaker Islam(11427188)
ITC 355 Server Administration and Maintenance
Assignment 2 Page 5
Crontab, ND, from
http://www.opengroup.org/onlinepubs/000095399/utilities/cr
ontab.html

Linux Crontab:15 Awesome Crontab Example,


SathiyaMoorthy, from
http://www.thegeekstuff.com/2009/06/15-practical-crontab-
examples/

Crontab Cronjob Examples, ND, from


http://www.monetizers.com/cronjob.php

MySQL:: MySQL 5.0 Reference Manual, ND,


http://dev.mysql.com/doc/refman/5.0/en/backup-
methods.html

Writing perl script to take backup with mysqldump, ND, from


http://stackoverflow.com/questions/4706078/writing-perl-
script-to-take-mysql-incremental-backup-with-mysqldump

Khandaker Islam(11427188)
ITC 355 Server Administration and Maintenance
Assignment 2 Page 6