Pages

Friday, 8 February 2013

Install and Configure Amanda Backup Server

I am going to setup Amanda backup into our office’s server to enable network backup to all of our servers located in different geographical area. The idea will be as below:


All servers are running on CentOS 6 64bit with iptables and SELINUX have been turned off.




Install Amanda Server

1. Install amanda packages using yum:

$ yum install -y amanda*

2. Create the configuration file. I am going to name this backup project is ServerNetBackup. We need to create a directory named by this project and all configuration files for this project will be underneath it:

$ mkdir /etc/amanda/ServerNetBackup

3. Create the core configuration file, amanda.conf:

$ vim /etc/amanda/ServerNetBackup/amanda.conf

And paste following line:

org "ServerNetBackup"                 # Organization name for reports
mailto "address@youremail.com"        # Email address to receive reports
netusage 10000 Kbps                   # Bandwidth limit, 10M

dumpcycle 1 week                      # Backup cycle is 7 days
runspercycle 7                        # Run 7 times every 7 days
tapecycle 15 tapes                    # Dump to 15 different tapes during the cycle
tpchanger "chg-disk"                  # The tape-changer glue script

changerfile "/etc/amanda/ServerNetBackup/changer"     # The tape-changer file

tapedev "file://central_backup/ServerNetBackup/slots" # The no-rewind tape device to be used
tapetype HARDDISK                                     # Define the type of tape

infofile "/etc/amanda/ServerNetBackup/curinfo"        # Database directory
logdir "/etc/amanda/ServerNetBackup/logs"             # Log directory
indexdir "/etc/amanda/ServerNetBackup/index"          # Index directory

define tapetype HARDDISK {                            # Define our tape behaviour
length 100000 mbytes                                  # Every tape is 100GB in size
}

amrecover_changer "changer"                           # Changer for amrecover

define dumptype global {                              # The global dump definition
maxdumps 2                                            # The maximum number of backups run in parallel
estimate calcsize                                     # Estimate the backup size before dump
holdingdisk yes                                       # Dump to temp disk (holdingdisk) before backup to tape
index yes                                             # Generate index. For restoration usage
}

define dumptype root-tar {                            # How to dump root's directory
global                                                # Include global (as above)
program "GNUTAR"                                      # Program name for compress
comment "root partitions dumped with tar"
compress none                                         # No compress
index                                                 # Index this dump
priority low                                          # Priority level
}

define dumptype user-tar {                            # How to dump user's directory
root-tar                                              # Include root-tar (as above)
comment "user partitions dumped with tar"
priority medium                                       # Priority level
}

define dumptype comp-user-tar {                       # How to dump & compress user's directory
user-tar                                              # Include user-tar (as above)
compress client fast                                  # Compress in client side with less CPU (fast)
}

Configure Backup Location

1. Prepare the directory to store all backups:

$ mkdir -p /central_backup/ServerNetBackup/slots

2. Assign correct permission to user amandabackup for the configuration directory and backup directory:

$ chown amandabackup.disk /central_backup -Rf
$ chown amandabackup.disk /etc/amanda/ServerNetBackup -Rf

3. Login as user amandabackup:

$ su - amandabackup

4. Create the virtual tape. This is where the backup files will be stored. We will need to create 15 slots as per tapecycle keyword:

$ for n in `seq 1 15`; do mkdir /central_backup/ServerNetBackup/slots/slot${n}; done

5. We then need to label all slots:

$ for n in `seq 1 15` ; do amlabel ServerNetBackup ServerNetBackup-${n} slot ${n}; done

4. Create all required directories as defined in the configuration file:

$ mkdir /etc/amanda/ServerNetBackup/curinfo
$ mkdir /etc/amanda/ServerNetBackup/logs
$ mkdir /etc/amanda/ServerNetBackup/index

Configure Service and What to Backup

1. We need to define what to backup in a file called disklist. As user amandabackup, create this file:

$ su - amandabackup
$ vim /etc/amanda/ServerNetBackup/disklist

And add following line:

sv101.krispykream.net /home/webby/public_html   comp-user-tar
gogogo.my-server.org  /etc                      root-tar

Notes: Make sure the hostname is FQDN and can be resolved to an IP. Add the host entry into /etc/hosts is recomended.

2. Exit from amandabackup user and get back to root user:

$ exit

3. Enable amanda service in xinetd.d directory:

$ vim /etc/xinetd.d/amanda

And change following line from “yes” to “no”:

disable = no

4. Enable on boot and restart xinetd service:

$ chkconfig xinetd on
$ service xinetd restart

5. Check the amanda server whether it is running properly by using following command:

$ netstat -a | grep amanda
udp        0          0       *:amanda                *:*

If you see result as above, amanda server is ready to serve!


Install Amanda Backup Client

1. Login to the client’s server and install required package for Amanda using yum:

$ yum install -y amanda amanda-client

2. As user amandabackup, add following line into /var/lib/amanda/.amandahosts to specify where is Amanda backup server:

$ su - amandabackup
$ vim /var/lib/amanda/.amandahosts

And make sure the value as below:

office.servering.com amandabackup amdump
localhost amandabackup amdump
localhost.localdomain amandabackup amdump

3. Exit from user amandabackup and turn to root user:

$ exit

4. Enable amanda service in xinetd.d directory:

$ vim /etc/xinetd.d/amanda

And change following line from “yes” to “no”:

disable = no

5. Enable on boot and start the xinetd service:

$ chkconfig xinetd on
$ service xinetd start

6. Add an entry in /etc/hosts to define backup server IP by adding following line:

125.10.90.90      office.servering.com

7. In some case, you may need to change the permission of the directory that you want to backup. For example, I need to allow user amandabackup to access directory /home/webby/public_html to create backup:

As root user, change the permission of the directory:

$ chmod 755 /home/webby

Run the Backup Process

1. Now go back to the Amanda server and check our configuration file as amandabackup user:

$ su - amandabackup
$ amcheck ServerNetBackup

You should see the output similar to this:

Client check: 2 host checked in 2.070 seconds.  0 problems found.

2.  If no error found, you can start the backup process immediately by running following command:

$ amdump ServerNetBackup

Or, we can automate this process using cronjob. Run following command as amandabackup user:

$ crontab -e

And add following line:

45 0 * * 2-6 /usr/sbin/amdump ServerNetBackup

3. As root user, reload the crond service to activate this job:

$ service crond reload

If the backup process completed, you should receive an email with backup report. In this email, it will tell you where is the backup location and process summary. I will continue on Amanda restoration process on the next post!

Update: I just updated this post on 5th Feb 2013 to use yum repository instead of package from zmanda.

from http://blog.secaserver.com/2012/09/centos-install-configure-amanda-backup-server/
-------------------------------------------------

Restore from Amanda Backup



So I have Amanda backup server configured in 2 servers as refer to my previous post here. In that setting, I was using Amanda to backup one of the server’s directory /home/webby/public_html in server sv101.krispykream.net. Now I need to restore all files in directory/home/webby/public_html/blog from latest backup.


 Configure Amanda Client for Restore

1. Login into the Amanda client, in my case is this server, sv101.krispykream.net as root. Create a new text file called amanda-client.conf. This file will define the server details that client is going to connect to for restoration:

$ vim /etc/amanda/amanda-client.conf

And add following line:

conf "ServerNetBackup"                # your config name in Amanda server

index_server "office.servering.com"   # your amindexd server
tape_server "office.servering.com"    # your amidxtaped server

ssh_keys ""                           # your ssh keys file if you use ssh auth
unreserved-tcp-port 1025,65535

2. Restart Amanda client service in this server:

$ service xinetd restart

3. Then, we need to login to the Amanda backup server, as in my case is office.servering.com to change the server_args under /etc/xinetd.d/amanda. This will allow Amanda clients to browse the index and tape in Amanda server:

$ vim /etc/xinetd.d/amanda

And change following line to be as below:

server_args             = -auth=bsd amdump amindexd amidxtaped

4. Restart xinetd service:

$ service xinetd restart


Restoring Files

1. To restore files, you simply need to login to the client with root user. The process flow will be as below:

Login to client > Go to the directory that you want to restore > Access Amanda server using amrecover > Select which disk > Select which date > Add into restoration list > Extract > Done

2. So now I am login to sv101.krispykream.net as root and navigate to the folder that I want to restore. I am going to restore all files in directory/home/webby/public_html/blog from latest backup because this directory has been accidentally deleted from the server:

$ cd /home/webby/public_html

3.  Connect to Amanda server using following command:

$ amrecover ServerNetBackup -s office.servering.com

AMRECOVER Version 2.6.1p2. Contacting server on office.servering.com ...
220 amanda AMANDA index server (2.6.1p2) ready.
Setting restore date to today (2013-02-06)
200 Working date set to 2013-02-06.
200 Config set to ServerNetBackup.
200 Dump host set to sv101.krispykream.net.
Use the setdisk command to choose dump disk to recover

4. Lets list the disk for this host in Amanda backup server:

amrecover> listdisk
200- List of disk for host sv101.krispykream.net
201- /home/webby/public_html
200 List of disk for host sv101.krispykream.net

5. Choose the disk for this backup:

amrecover> setdisk /home/webby/public_html
200 Disk set to /home/webby/public_html.

6. I do not know which tape that holding the latest backup, so I will use history command to list it out all:

amrecover> history
200- Dump history for config "ServerNetBackup" host "sv101.krispykream.net" disk /home/webby/public_html
201- 2013-02-05-18-29-38  0  ServerNetBackup-2:1
201- 2013-02-05-13-00-58  0  ServerNetBackup-1:1
201- 2013-02-05-12-59-41  0  ServerNetBackup-15:1
200 Dump history for config "ServerNetBackup" host "sv101.krispykream.net" disk /home/webby/public_html

7. Now I should choose the latest backup which is 2013-02-05-18-29-38, which means the backup is create at 6:29:38 PM on 5th of February 2013:

amrecover> setdate 2013-02-05-18-29-38
200 Working date set to 2013-02-05-18-29-38.

8. I have chosen the backup and tape to the latest date. I can then list out all the files in this backup directory as below:

amrecover> ls
2013-02-05-18-29-38 web.config.txt
2013-02-05-18-29-38 tmp/
2013-02-05-18-29-38 test/
2013-02-05-18-29-38 templates/
2013-02-05-18-29-38 robots.txt
2013-02-05-18-29-38 plugins/
2013-02-05-18-29-38 modules/
2013-02-05-18-29-38 media/
2013-02-05-18-29-38 logs/
2013-02-05-18-29-38 libraries/
2013-02-05-18-29-38 language/
2013-02-05-18-29-38 joomla.xml
2013-02-05-18-29-38 installation/
2013-02-05-18-29-38 index.php
2013-02-05-18-29-38 includes/
2013-02-05-18-29-38 images/
2013-02-05-18-29-38 htaccess.txt
2013-02-05-18-29-38 components/
2013-02-05-18-29-38 cli/
2013-02-05-18-29-38 cache/
2013-02-05-18-29-38 blog/
2013-02-05-18-29-38 administrator/
2013-02-05-18-29-38 README.txt
2013-02-05-18-29-38 LICENSE.txt
2013-02-05-18-29-38 .

9. Since I just want to restore blog directory, I will need to add blog into extraction list:

amrecover> add blog
Added dir /blog/ at date 2013-02-05-18-29-38

10. Once added, we can extract the backup to the working directory as below:

amrecover> extract

Extracting files using tape drive changer on host office.servering.com.
The following tapes are needed: ServerNetBackup-2

Restoring files into directory /home/webby/public_html
Continue [?/Y/n]? Y

Extracting files using tape drive changer on host office.servering.com.
Load tape ServerNetBackup-2 now
Continue [?/Y/n/s/d]? Y

It will then restore all your files into the working directory. Just exit the amrecover console and you can see the restored directory will be exist there, as example below:

$ ls -al | grep blog
drwxr-xr-x   5    webby  webby    4096    Jan 25 04:53    blog

Restoration complete!

from http://blog.secaserver.com/2013/02/centos-restore-recover-amanda-backup/