Chinaunix首页 | 论坛 | 博客
  • 博客访问: 331151
  • 博文数量: 85
  • 博客积分: 1420
  • 博客等级: 上尉
  • 技术积分: 787
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-10 09:02
文章分类

全部博文(85)

文章存档

2011年(5)

2010年(51)

2009年(29)

我的朋友

分类: LINUX

2010-05-18 23:42:27

Synbak is a command line tool for backing up data. It makes use of a number of utilities commonly found on Linux systems, and employs several applications to back up different types of data. It is modular in nature, making it easy to add new backup tools and support for other types of backup media. It already supports a wide range of options.

Synbak can make backups using:

- RSync over ssh, rsync daemon, smb and cifs protocols (using internal automount functions)

- Tar archives (tar, tar.gz and tar.bz2)

- Tape devices (using multi loader changer tapes too)

- LDAP databases

- MySQL databases

- Oracle databases

- PostgreSQL databases

- CD-RW/DVD-RW

- Wget to mirror HTTP/FTP servers

- DAR (a newly added backup method, not fully tested yet)

It also has extensive report generating facilities, covering email reports, HTML reports or RSS reports. It employs simple command line options, which make it ideal for automated use as a cron event.

[] Requirements

Synbak makes extensive use of software commonly found in Linux distributions. The only support software not part of a standard Zenwalk install is bc (which I think should be included). Backup software covers a wider range, but will vary somewhat depending on what type of backups are to be run, and what type of backup devices are to be used. The list of backup utilities is as below:

  • GNU tar
  • mtx
  • mt-tools
  • rsync
  • samba
  • mysqldump
  • exp (oracle's export command)
  • ldapsearch
  • mount.cifs or smbmount

mtx is only required if SCSI changer devices are to be used. mt-tools is only required to control tape drives.


[] Configuration

Synbak requires a good deal of configuration before it can be used. By the nature of the package, this configuration needs to be done manually.

Once the package has been installed, it is necessary to create some directories. Some are default and can be changed to suit local conditions, and some are required in order to operate the software. First, Synbak requires a configuration directory under the home directory of the user who will be running it. This can be any user, so long as they have read permissions to the files to be backed up, and write permissions to the media to which the backup is to be written.

To set Synbak up for a user, open a terminal logged in as that user (or su to root for system wide backups). Once that is done, enter the following commands:

cd ; mkdir .synbak ; cd .synbak

Once the initial directory has been created, it is necessary to select a backup method. As an example, to use tar as a backup method, follow up by entering the following commands:

mkdir tar ; cd tar ; cp /usr/share/synbak/template.conf .conf

This creates the directory for the tar method and copies a sample configuration file into it. Note that the configuration file is named according to the system (which would normally be the hostname of the system to be backed up).

As well as the configuration directories, it is also necessary to create a directory for HTML reports (unless this feature is to be disabled). By default, the report directory is as below:

/var/www/html/admin/log/backup

That path can be changed to suit the local system, but the path must exist and be entered in the method configuration file.

The next step is to edit the configuration to set up the backup. The configuration template copied above has a wide range of options, only some of which apply to use with tar. The important options are listed below:

#@@ mandatory backup fields
backup_source = /bin /boot /etc /home /lib* /root /sbin /srv /tmp /usr /var
backup_destination = /srv/backup/$system/$method
backup_exclude = /srv/backup *.tmp

The fields above set up the data to be backed up, the destination of the backup and a list of files or wild card file templates to exclude from the backup. They also illustrate some of the environment variables that Synbak is able to use ($system and $method). As already mentioned, whatever user account is employed to make the backup must have read permissions for the files to be backed up, and must also have write permissions for the backup destination.

The backup destination can be very flexible. A directory on the local hard drive, a network share, either Samba or NFS, or a removable drive are the most likely destinations for a tar backup. Placing a backup on the drive being backed up is less than ideal, so one of the remote options is probably the best choice. Which of them is chosen will depend on available resources and the local situation.

Synbak's exclusion filter is very useful indeed. For example, using Cache/* will exclude the cache directories for Seamonkey or Iceweasel. The directory will be created in the backup, but none of its contents will be copied to the backup.

backup_incremental      = yes
backup_erase_after = 7 # auto erase old backups after n. backup
backup_no_make_destdir = no # don't make the auto created destinatio
backup_erase_always = no # erase old backups even if an error occurs
backup_method_opts =
#@@ tape and tar backup
backup_verify = yes

The incremental option does not apply to tar backups. but can be ignored.

backup_erase_after allows multiple generations of backup to be kept. After the specified number, backup sets will be deleted on a FIFO basis

backup_no_make_destdir would allow the system to create destination directories if they don't already exist. Safest left as no.

backup_erase_always with the 'no' default means that, if an error occurs, older backup sets will not be deleted. In most circumstances the default should be left alone.

backup_method_opts allows the end user to enter extra options that apply to the backup method being used.

backup_verify can be used so the backup set is verified after being written.

The next section that should be checked covers reporting options. The first option is email:

#@@ email output reporting
report_email = no # always generate an email report
report_email_on_errors = yes # generate email report on errors only
report_email_rcpt = root@localhost.localdomain # the detination address of email

By default, an email report will be generated only if an error occurs. In some circumstances, an email report can be generated for every backup option. It should be noted that the email options will not work on a standard Zenwalk installation, since it does not have an MTA (Mail Transfer Agent) as part of its standard software. If this option is to be used, a package such as Sendmail or Qmail will need to be installed and configured.

The other common reporting option is done by the generation of HTML files:

#@@ html/rss output reporting
report_html = yes # always generate a html report
report_html_on_errors = yes # generate html on errors only
report_html_destination = /var/www/html/admin/log/backup # destination dir
report_html_uri = # uri of html and rss reports
report_html_logo = yes # display a logo in the html report
report_html_logo_image =
report_html_logo_link =

These options control the generation of and access to HTML or RSS reporting features. On a Zenwalk install, this is probably the best option. Unless a web server is running, the HTML reports need to be accessed by opening index.html in the directory specified.

With configuration completed, backups can be started. In its simplest form, the following command will create a compressed tar archive of the specified files:

synbak -s  -m tar -M gz

[] Examples

Desktop Backup

While this is an example that can be applied to any desktop machine, it is taken from a server backup. The backup destination is a NAS unit which is mounted before the backups begin, then unmounted when the backup is complete. The (edited) configuration is below:

#@ Synbak 1.2.x main configuration file
#@ Special system variables usable in this config file (they are case sensitive):
# - $system (the system name specified in the command line)
# - $method (the method name specified in the command line)
# - $today (today date, in format YYYYMMDD, ex. '20030920')
# - $onedayago (1 day ago date, in format YYYYMMDD, ex. '20030919')
# - $twodayago (2 day ago date, in format YYYYMMDD, ex. '20030918')
# - $threedayago (3 day ago date, in format YYYYMMDD, ex. '20030917')
# - $xxxdayago (so on...)
# - $HOME (your home directory, ex. '/home/username')

#@@ mandatory backup fields
backup_source = /boot/grub /etc /home /root /var
backup_destination = /mnt/smb/backup
backup_exclude = *.tmp .Trash/* .junkmail/*

backup_incremental = yes
backup_erase_after = 7
backup_no_make_destdir = no
backup_erase_always = no
backup_method_opts =
#backup_verify = yes
#@@ misc reporting information
report_info_support = support@mcp.co.uk
#@@ standard output reporting
report_stdout = no
report_stdout_on_errors = no
#@@ email output reporting
report_email = no
report_email_on_errors = yes
report_email_rcpt = support@mcp.co.uk
#@@ html/rss output reporting
report_html = no
report_html_on_errors = no
report_html_destination = /var/www/html/admin/log/backup
report_html_uri =
report_html_logo = yes
report_html_logo_image =
report_html_logo_link =

Since this is a server (and doesn't run Xwindows), HTML/RSS reporting is disabled, and email reporting is enabled. Also, since the backup is set to be run from a cron event, Synbak's reporting to standard out is disabled (though it can be easily re-enabled if a backup has to be carried out manually). Seven generations of backup are kept, and old backups are not deleted if an error occurs.

Since the backup is carried out entirely unattended, a simple wrapper script is used to handle mounting and unmounting the Samba share (in this case the share is on a Zyxel NSA220 NAS device):

#!/bin/bash
# Mount Samba share using CIFS, check that the mount has worked, then call
# Synbak to backup. Share is open, so no username/password is required.
# Log an error message if the mount command fails.
mount -t cifs -o guest //192.168.0.225/srv1 /mnt/smb
sleep 4
if [ -d /mnt/smb/backup ]; then
/usr/bin/synbak -s server1 -m tar -M gz
sleep 20
umount /mnt/smb; exit
else
echo "`date +%m-%d-%H:%M` Mount failed, backup aborted" >> /var/log/synbak.log
fi

CIFS is used rather than SMBFS, to avoid problems with large files. The wrapper script is called by a cron event as below:

30 3 * * * root /root/bin/tarback

(tarback is the name given to the wrapper, and the cron version used requires a user name to operate.Using this entry, a Synbak backup will run at 0330 every day)

Laptop Backup

The laptop is slightly different. While it is sometimes on a network, it often is not. It is also useful to have backup data in a form that can be carried around. As a result, the backup (also a gzipped tar archive) is made to a USB hard drive. Configuration is as below:

#@ Synbak 1.2.x main configuration file

#@ Special system variables usable in this config file (they are case sensitive):
# - $system (the system name you specified in command line)
# - $method (the method name you specified in command line)
# - $today (today date, in format YYYYMMDD, ex. '20030920')
# - $onedayago (1 day ago date, in format YYYYMMDD, ex. '20030919')
# - $twodayago (2 day ago date, in format YYYYMMDD, ex. '20030918')
# - $threedayago (3 day ago date, in format YYYYMMDD, ex. '20030917')
# - $xxxdayago (so on...)
# - $HOME (your home directory, ex. '/home/username')

#@@ mandatory backup fields
backup_source = /boot /etc /home/tooth
backup_destination = /media/DataTrans/backup/$system/$method
backup_exclude = Cache/* *.swp *.tmp *.iso *.md5
backup_incremental = yes
backup_erase_after = 7
backup_no_make_destdir = no
backup_erase_always = no
backup_method_opts =
#@@ standard output reporting
report_stdout = yes
report_stdout_on_errors = no
#@@ email output reporting
report_email = no
report_email_on_errors = no
report_email_rcpt = support@initzero.it
#@@ html/rss output reporting
report_html = yes
report_html_on_errors = yes
report_html_destination = /var/www/html/admin/log/backup
report_html_uri =
report_html_logo = yes
report_html_logo_image =
report_html_logo_link = /

Laziness suggests another wrapper script to run this backup as well - backit:

#!/bin/bash
if [ -d /media/DataTrans/backup ]; then
echo 'removable is mounted'
synbak -s t-42 -m tar -M gz
else
echo 'sorry, no media present' ; exit
fi


[] Limitations

Flexible though Synbak is, it does have some limitations.

- optical disk support is limited to read-write, no support for write-once media

- PostgreSQL support requires an open account for backup purposes

- no control over archive size when using Tar and compressed Tar archives

- using wget for http backups requires an absolute path (so it cannot be used to backup a user's web space unless the user knows the absolute path to the space)

[] DAR

DAR (Disk ARchive) support is a recent addition to Synbak, and is somewhat limited so far. However, since DAR has a number of useful features, it is worth mentioning. It helps overcome the problem of archive size control, since DAR has the ability to set a maximum archive size. In addition, DAR is smart enough to allow specific file types to be stored without compression, allowing for faster and more efficient backups.

While there are not yet any options (other than file include/exclude filters) that apply to using the DAR backup method, other settings can be made in ~/.darrc or /etc/darrc. This allows things like maximum "slice" size, global file exclusions, and file types to store without compression to be set.

DAR can be used on its own, so one might ask why Synbak is necessary. The simple answer is that the DAR command line is complex, especially if multiple directories are to be selectively backed up. Synbak offers a much simpler way of controlling DAR, making both programs a very good combination.

While DAR is not yet in the Zenwalk repositories, a Zenwalk build of the most recent version of DAR can be found here:

阅读(1036) | 评论(0) | 转发(0) |
0

上一篇:configure参数

下一篇:时隙

给主人留下些什么吧!~~