Difference between revisions of "Rsnapshot"

From Amahi Wiki
Jump to: navigation, search
 
(50 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[http://rsnapshot.org/ '''''rnapshot'''''] is an excellent backup application and has been around for a long time and is extremely stable.  
+
{{NeedsUpdate}}
 +
[http://rsnapshot.org/ '''''rsnapshot'''''] is an excellent backup application and has been around for a long time and is extremely stable.  
  
 
Why are backups important? Well, hardware failures, accidental file deletion(s), files become corrupted, etc.. Backups can help recover data where applications are being updated/upgraded. Enough reasons?   
 
Why are backups important? Well, hardware failures, accidental file deletion(s), files become corrupted, etc.. Backups can help recover data where applications are being updated/upgraded. Enough reasons?   
Line 20: Line 21:
 
=== Preparing an External USB Drive ===
 
=== Preparing an External USB Drive ===
  
Off-the-shelf external USB drives normally are setup to work with computers that utilize CIFS type filesystems. rsnapshot uses a "hard links" feature that is unique to Linux/Unix filesystems (ext3). "Hard Links" are not supported on filesystems such as: '''"smbfs"''', '''"Samba (SMB)"''', '''"FAT"''', '''"FAT32"''', '''"NTFS"''', '''"CIFS"''', '''"vfat"'''. Please note that "Amahi Greyhole" mounts Amahi shares that look like "local disk drives" '''''but''''' these are Samba (SMB) mounted shares. The external disk drive will have to be prepared  for a Linux/Unix filesystem, in particular ext3. Why? ext3 has been around for sometime, is stable, and "Windows" computers have Open Source drivers available that can be installed to gain access to an ext3 drive.
+
Off-the-shelf external USB drives normally are setup to work with computers that utilize CIFS type filesystems. rsnapshot uses a "hard links" feature that is unique to Linux/Unix filesystems (ext3). "Hard Links" are not supported on filesystems such as: '''"smbfs"''', '''"Samba (SMB)"''', '''"FAT"''', '''"FAT32"''', '''"NTFS"''', '''"CIFS"''', '''"vfat"'''. Please note that "Amahi Greyhole" mounts Amahi shares that will look like "local disk drives" '''''but''''' these are Samba (SMB) mounted shares. An external disk drive will have to be prepared  for a Linux/Unix filesystem, in particular ext3. Why? ext3 has been around for sometime, is stable, and "Windows" computers have Open Source drivers available that can be installed to gain access to an ext3 drive.
  
 
Prepare an external drive for ext3 as follows:
 
Prepare an external drive for ext3 as follows:
Line 26: Line 27:
 
* The external USB drive used in this example is a 1 Terabyte (1 TB) Seagate drive.
 
* The external USB drive used in this example is a 1 Terabyte (1 TB) Seagate drive.
 
* Plug the drive in to a USB connector and power it up.
 
* Plug the drive in to a USB connector and power it up.
* Using a "terminal session, login in using the "root" user ID.
+
* Using a "terminal" session, login in using the "root" user ID.
 
* The "device name" of the drive needs to be determined.
 
* The "device name" of the drive needs to be determined.
<blockquote>Enter the following command:
 
{{Code|dmesg}}
 
</blockquote>
 
  
<blockquote>The following information is displayed:
+
 
{{Text|Text=[11122.304178] usb 2-4: new high-speed USB device number 5 using ehci_hcd
+
Enter the following command:
 +
dmesg
 +
 
 +
The following information is displayed:
 +
<pre>[11122.304178] usb 2-4: new high-speed USB device number 5 using ehci_hcd
 
[11122.422152] usb 2-4: New USB device found, idVendor=0bc2, idProduct=3320
 
[11122.422152] usb 2-4: New USB device found, idVendor=0bc2, idProduct=3320
 
[11122.422165] usb 2-4: New USB device strings: Mfr=2, Product=3, SerialNumber=1
 
[11122.422165] usb 2-4: New USB device strings: Mfr=2, Product=3, SerialNumber=1
Line 43: Line 45:
 
                     .
 
                     .
 
                     .
 
                     .
[11123.516813]  sdb: sdb1
+
[11123.516813]  sdb: sdb1</pre>
}}
 
</blockquote>
 
 
* The "device name" is "sdb1".
 
* The "device name" is "sdb1".
 
* The USB drive needs to be "unmounted".
 
* The USB drive needs to be "unmounted".
<blockquote>
+
 
{{Code|umount /dev/sdb1}}
+
umount /dev/sdb1
</blockquote>
+
 
 
* Format drive for ext3 filesystem and set drive label name as "usbdisk".
 
* Format drive for ext3 filesystem and set drive label name as "usbdisk".
<blockquote>
+
 
{{Code|mkfs -t ext3 -v -L usbdisk /dev/sdb1}}
+
mkfs -t ext3 -v -L usbdisk /dev/sdb1
</blockquote>
+
 
  
 
:'''Please Note: THIS WILL ERASE ALL DATA ON /dev/sdb1,  MAKE SURE THIS IS THE CORRECT USB DRIVE AND NOT ANOTHER DRIVE.'''
 
:'''Please Note: THIS WILL ERASE ALL DATA ON /dev/sdb1,  MAKE SURE THIS IS THE CORRECT USB DRIVE AND NOT ANOTHER DRIVE.'''
<blockquote>The following information is displayed:
+
 
{{Text|Text=mke2fs 1.42.5 (29-Jul-2012)
+
The following information is displayed:
 +
<pre>mke2fs 1.42.5 (29-Jul-2012)
 
fs_types for mke2fs.conf resolution: 'ext3'
 
fs_types for mke2fs.conf resolution: 'ext3'
 
Filesystem label=usbdisk
 
Filesystem label=usbdisk
Line 67: Line 68:
 
                     .
 
                     .
 
                     .
 
                     .
Writing superblocks and filesystem accounting information: done
+
Writing superblocks and filesystem accounting information: done</pre>
}}
 
</blockquote>
 
 
* Whenever a drive is formatted in Linux, about 5% is reserved of the total space on the drive for the operating system to continue using the hard drive to operate, even if it gets full. This is totally unnecessary for a USB external hard drive if it stores only data and not to run an operating system.
 
* Whenever a drive is formatted in Linux, about 5% is reserved of the total space on the drive for the operating system to continue using the hard drive to operate, even if it gets full. This is totally unnecessary for a USB external hard drive if it stores only data and not to run an operating system.
<blockquote>Enter the following to remove the reserved space:
+
 
{{Code|tune2fs -m 0 /dev/sdb1}}
+
 
</blockquote>
+
Enter the following to remove the reserved space:
<blockquote>The following information is displayed:
+
tune2fs -m 0 /dev/sdb1
{{Text|Text=tune2fs 1.42.5 (29-Jul-2012)
+
 
Setting reserved blocks percentage to 0% (0 blocks)
+
The following information is displayed:
}}
+
tune2fs 1.42.5 (29-Jul-2012)
 +
Setting reserved blocks percentage to 0% (0 blocks)
 +
 
 
* The external drive is now ready for use.
 
* The external drive is now ready for use.
  
Line 88: Line 89:
 
* In the previous section the device name found found via the "dmesg" command. The device name found was "sdb1".
 
* In the previous section the device name found found via the "dmesg" command. The device name found was "sdb1".
 
* We set the set the external drive's "label". It was set to "usbdisk".
 
* We set the set the external drive's "label". It was set to "usbdisk".
<blockquote>To find the label at anytime via the "root" user ID enter:
+
 
{{Code|e2label /dev/sdb1}}
+
 
</blockquote>
+
To find the label at anytime via the "root" user ID enter:
<blockquote>The following information is displayed:
+
e2label /dev/sdb1
{{Text|Text=usbdisk}}
+
 
</blockquote>
+
The following information is displayed:
 +
usbdisk
 +
 
 +
Both methods of mounting will be controlled by the server's "fstab" configuration file. The fstab (a.k.a. file systems table) file is a system configuration file containing lists of available disks and disk partitions, and indicates how they are to be initialized or otherwise integrated into a system's file system. When the "mount" command is used, the fstab file is read to determine which options should be used when mounting a specified device.
 +
 
 
==== Auto-Mounting ====
 
==== Auto-Mounting ====
  
To Auto-mount your usbdisk (so the backup will work after a reboot) do the following:
+
Auto-mount of an external USB drive will occur when a server "boots" or "reboots". Provided the fstab configuration file is properly configured. A powered up USB drive that is plugged in after a server has completed the boot process is not auto-mounted. However, using a "terminal" session with the "root" user ID, and issuing a "mount -a" command will mount an external USB drive.
  
:cp /etc/fstab /etc/fstab_bak
+
Configure fstab to auto-mount an external USB drive do the following:
  
:nano /etc/fstab
+
* Start a "terminal" session login to the "root" user ID.
  
Add to this file
+
* Navigate to the "etc" directory with the "cd" command and make a backup of the current fstab file.
 +
cd /etc
 +
cp /fstab /fstab_bak
  
:LABEL=usbdisk        /media/usbdisk      ext3    defaults        0 0
+
* Using a preferred file editor (i.e. vi, nano), open the fstab file.
 +
fstab
  
Save the file.
+
* Near the bottom of the and after the other fstab entries, add the following:
 +
 
 +
LABEL=usbdisk        /media/usbdisk      ext3    defaults        0 0
 +
 
 +
* Now save the fstab file and exit the editor.
 +
* Navigate to the /media directory and create a "usbdisk" directory. This is where the external drive will be mounted, this is called a "mount point".
 +
cd /media
 +
mkdir usbdisk
 +
 
 +
* Make sure the external drive USB cable is connected to the server and is powered up.
 +
* Reboot the server.
 +
* Remember the disk label set earlier when formatting the drive? During the boot process when the "LABEL" is read, this instructs the system to find a hard disk with the label "usbdrive", and then mounts it to the mount point, "/media/usbdisk".
  
 
==== Manual Mounting ====
 
==== Manual Mounting ====
 +
Mount of an external USB drive will not occur when a server "boots" or "reboots" when the fstab configuration file is configured for manual mounting. A powered up USB drive that is plugged in after a server has completed the boot process is also not mounted.
 +
 +
Configure fstab for a manual mounting of an external USB drive with the following:
 +
 +
* Start a "terminal" session login as the "root" user ID.
 +
 +
* Navigate to the "etc" directory with the "cd" command and make a backup of the current fstab file.
 +
cd /etc
 +
cp /fstab /fstab_bak
 +
 +
* Using a preferred file editor (i.e. vi, nano), open the fstab file.
 +
nano fstab
  
< TBA >
+
* Near the bottom of the and after the other fstab entries, add the following:
 +
LABEL=usbdisk /media/usbdrive ext3 rw,noauto,users,exec,noatime 0 0
  
===Install rsnapshot===
+
* Now save the fstab file and exit the editor.
:yum install rsnapshot
+
* Navigate to the /media directory and create a "usbdisk" directory. This is where the external drive will be mounted, this is called a "mount point".
 +
cd /media
 +
mkdir usbdrive
 +
* Make sure the external drive USB cable is connected to the server and is powered up.
 +
* Reboot the server.
 +
* Start a "terminal" session login as the "root" user ID.
 +
* To manually mount the external drive issue the following command:
 +
mount -L usbdisk
 +
* The system reads the fstab, when it finds a line entry with the label "usbdrive", it mounts the drive the mount point, "/media/usbdisk".
  
:mkdir -p /media/usbdisk/.private/.snapshots
+
==== Unmounting ====
  
:chmod 0700 /media/usbdisk/.private/
+
With both mounting methods the external drive can be unmounted by the following:
  
:chmod 0755 /media/usbdisk/.private/.snapshots/  
+
* Start a "terminal" session login as the "root" user ID.
 +
* Issue the following command to unmount the external drive:
 +
umount /media/usbdrive
 +
* Should an error occur indicating that the drive is busy and cannot be unmounted enter the command below. Then try the unmount command again.
 +
fuser -km /media
  
===Quick rsnapshot Recipe===
+
===Installing rsnapshot===
 +
rsnapshot is available as a package in both the Fedora and Ubuntu Linux distributions. The installation shown here is based on Fedora.
  
Here is a quick recipe to configure rsnapshot.
+
* Open a "terminal" session and login using the "root" user ID:
  
These are the critical settings in /etc/rsnapshot.conf:
+
yum install rsnapshot
  
    snapshot_root  /mnt/1tb-external/snapshots/
+
* Now create the directory structures for storing the backups:
    interval        daily  14
 
    interval        weekly  4
 
    interval        monthly 4
 
  
This will create a series of directories called daily.0 through daily.13
+
mkdir -p /media/usbdisk/.private/.snapshots
weekly.0 to weekly.3 ... etc.
+
chmod 0700 /media/usbdisk/.private/
 +
chmod 0755 /media/usbdisk/.private/.snapshots/
  
===Another example of rsnapshot configuration on amahi 5.1===
+
=== Configuring rsnapshot ===
In this example automated backups are made to an external usb drive.
+
This section shows how to configure the rsnapshot.conf configuration file.
Plug in the USB drive, it will probably mount automatically under /media/yourdisklabel
 
  
===Modify rsnapshot configuration===
+
* Open a "terminal" session and login to the "root" user ID.
:nano /etc/rsnapshot.conf
 
  
make the following modifications to the file rsnapshot.conf
+
* Move to the "/etc" directory.
for blank spaces use TABS!
 
  
:snapshot_root  /media/usbdisk/.private/.snapshots/
+
cd /etc
  
:no_create_root  1
+
* Make a backup copy of the rsnapshot configuration file. Why? So that there is a reference just in case.
  
:interval        hourly 6
+
  cp rsnapshot.conf rsnapshot.conf.bkup
  
:interval        daily  7
+
* Now using a favourite editor, open the "rnapshot.conf" file.
 +
<br/>
 +
'''Please Note:''' Items in the configuration file are separated by "tab" characters and NOT multiple spaces.
 +
nano rsnapshot.conf
  
:interval        weekly  4
+
* Find the "SNAPSHOT ROOT DIRECTORY" section and change "snapshot_root" to path where the backups will be stored.
  
:interval        monthly 12
+
snapshot_root /media/usbdisk/.private/.snapshots/}}
  
:verbose        3
+
* Find the "no_create_root" section and remove the "#". This will allow rsnapshot to create the "snapshot root" directory.
  
:backup /var/hda/files/docs/    localhost/
+
no_create_root  1
  
:backup /var/hda/files/pictures/ localhost/
+
* Find the "BACKUP INTERVALS" section and change the line items. What does this all mean? The "#" character at the beginning of each line means the configuration line item will not be enabled. Remove the "#" character as required. For example, when enabled the "interval daily" line will be active and 7 days of backups will be kept.
  
:backup /var/hda/files/movies/  localhost/
+
interval   hourly  6
 +
interval daily 7
 +
interval weekly 4
 +
interval monthly 12
  
:backup /var/hda/files/music/  localhost/
+
* Find the "GLOBAL OPTIONS" section. This section defines how much information will be saved in the rsnapshot "log" file.
 +
  The options are:
 +
 +
  Verbose level, 1 through 5.
 +
  1    Quiet          Print fatal errors only
 +
  2    Default        Print errors and warnings only
 +
  3    Verbose        Show equivalent shell commands being executed
 +
  4    Extra Verbose  Show extra verbose information
 +
  5    Debug mode      Everything
 +
Change the following options as required:
 +
verbose        3
 +
loglevel        3
  
:backup /var/hda/files/othersharesyoumade localhost/
+
* Find the "logfile" line and change the line item. After rsnapshot has completed backups this is where the resulting "log" file is stored. Change this line as required.
  
Save the file
+
logfile /var/log/rsnapshot}}
  
:rsnapshot configtest
+
* Find the "BACKUP POINTS / SCRIPTS" section. Add changes as seen below. This is the section that defines the "key directories" that will be backed up. Please note the "localhost/", this represents the server that it being backed up. "localhost/" is a default name given to the current server. Change this name as required, say "amahiBox/"?
  
this should return: syntax OK
+
backup /var/hda/files/docs/    localhost/
 +
backup /var/hda/files/pictures/ localhost/
 +
backup /var/hda/files/movies/  localhost/
 +
backup /var/hda/files/music/  localhost/
 +
backup /var/hda/files/other_shares_you_made localhost/
  
===Email reporting===
+
* Save the "rsnapshot.conf" file.
 +
 
 +
=== Test the Configuration Changes ===
 +
* Now the changes to the rsnapshot configuration file have to be tested. rsnapshot has a feature to test changes to make sure things have been setup correctly.
 +
 
 +
* Enter the following on the command-line to initiate the test.
 +
 
 +
rsnapshot configtest}}
 +
 
 +
* When the test completes the following should be displayed:
 +
 
 +
Syntax OK
 +
 
 +
* If an error occurs the rsnapshot configuration file will need to be checked.
  
for email reporting on your backups:
+
===Automate Backups ===
 +
Backups can be automated by creating a "cron job" that can be executed by the system at predetermined intervals.
  
:cp /usr/share/doc/rsnapshot*/utils/rsnapreport.pl /root
+
* Using a "terminal" session and "root" user ID a "cron job" configuration can be created to perform  automated backups.
 +
Create a "cronjobs" text file as follows:
 +
crontab -l > cronjobs
  
:chmod 744 rsnapreport.pl
+
* Using a favourite text editor open the cronjobs file.
  
===Automate backup with cronjob===
+
nano cronjobs
  
:crontab -l > cronjobs
+
* Add to the cronjobs file for rsnapshot:
  
:nano cronjobs
 
  
add to this file for running rsnapshot and a weekly email report on rsnapshot:
+
0 */4 * * *      /usr/bin/rsnapshot hourly
 +
30 23 * * *      /usr/bin/rsnapshot daily
 +
00 23 * * 1      /usr/bin/rsnapshot weekly
 +
30 22 1 * *      /usr/bin/rsnapshot monthly
  
:0 */4 * * *      /usr/bin/rsnapshot hourly 2>&1 | /root/rsnapreport.pl > /root/rsnapreport
+
* Save the cronjobs file.
 +
* Now update the "root" user IDs "crontab" with the following:
  
:30 23 * * *      /usr/bin/rsnapshot daily
+
crontab cronjobs}}
  
:00 23 * * 1      /usr/bin/rsnapshot weekly
+
* Reboot the server and rsnapshot will be operational.
  
:30 22 1 * *      /usr/bin/rsnapshot monthly
+
===Email reporting===
 +
* To email a report of backups:
  
:00 22 * * 6      /usr/bin/rsnapshot du >> /root/rsnapreport | nail –r "somereturnadress@provider.com" -s"HDA backup report" -S smtp=smtp.yourprovider.com youremail@provider.com < /root/rsnapreport
+
cp /usr/share/doc/rsnapshot*/utils/rsnapreport.pl /root
 +
chmod 744 rsnapreport.pl
 +
'''*''' above indicates an rsnapshot version number
  
Save the file
+
* Add the following to crontab for a weekly email report on rsnapshot:
  
:crontab cronjobs
+
<pre style="white-space: pre-wrap; word-break: keep-all;">0 */4 * * *      /usr/bin/rsnapshot hourly 2>&1 | /root/rsnapreport.pl > /root/rsnapreport
 +
00 22 * * 6      /usr/bin/rsnapshot du >> /root/rsnapreport | nail –r "somereturnadress@provider.com" -s"HDA backup report" -S smtp=smtp.yourprovider.com youremail@provider.com < /root/rsnapreport</pre>
  
Rsnapshot should now be operational.
+
'''Please Note:''' The above information maybe out of date due to technology changes. Please feel to update as required.
  
 
===Make your backups available on clients (READ ONLY)===
 
===Make your backups available on clients (READ ONLY)===
Line 213: Line 297:
 
Create a //hda/backup share in the HDA webinterface
 
Create a //hda/backup share in the HDA webinterface
  
:chkconfig nfs --level 2345 on
+
chkconfig nfs --level 2345 on
  
 
add a read only NFS export:
 
add a read only NFS export:
  
:nano /etc/exports
+
nano /etc/exports
  
 
add  
 
add  
  
:/media/usbdisk/.private/.snapshots/  127.0.0.1(ro,no_root_squash)
+
/media/usbdisk/.private/.snapshots/  127.0.0.1(ro,no_root_squash)
  
 
Save file
 
Save file
Line 227: Line 311:
 
Unfortunately mounting an NFS share in fstab did not work on my machine after a reboot, so I chose an alternative configuration that mounts the share later in the booting process:
 
Unfortunately mounting an NFS share in fstab did not work on my machine after a reboot, so I chose an alternative configuration that mounts the share later in the booting process:
  
:nano /etc/rc.local
+
nano /etc/rc.local
  
 
Add
 
Add
  
:mount -r -t nfs localhost:/media/usbdisk/.private/.snapshots/  /var/hda/files/backup/
+
mount -r -t nfs localhost:/media/usbdisk/.private/.snapshots/  /var/hda/files/backup/
  
 
save file
 
save file
  
 
[[Category: Apps]]
 
[[Category: Apps]]

Latest revision as of 03:23, 23 June 2020

Msgbox.update.png Update Needed
The contents of this page have become outdated or irrelevant. Please consider updating it.

rsnapshot is an excellent backup application and has been around for a long time and is extremely stable.

Why are backups important? Well, hardware failures, accidental file deletion(s), files become corrupted, etc.. Backups can help recover data where applications are being updated/upgraded. Enough reasons?

Where should backups be stored? Due to the inevitable failure of hardware it is desirable to store backups on a separate system from where the production data is stored. Or possibly to an external medium such as an external USB disk drive. This article discusses backing up to an external USB drive.

Please Note:

rnapshot depends on attributes that are unique to Linux/Unix (i.e. ext3, ext4) filesystems only. If backups to "CIFS" (Samba a.k.a. smb, fat, fat32, vfat, ntfs) filesystems are required a different backup application must be used (i.e. rdiff-backup).

Bk backup-recovery.png
Here is a good book that discusses backups, recoveries, rsnapshot and rdiff-backup:

"Backup & Recovery: Inexpensive Backup Solutions for Open Systems, by W. Curtis Preston".

Preparing an External USB Drive

Off-the-shelf external USB drives normally are setup to work with computers that utilize CIFS type filesystems. rsnapshot uses a "hard links" feature that is unique to Linux/Unix filesystems (ext3). "Hard Links" are not supported on filesystems such as: "smbfs", "Samba (SMB)", "FAT", "FAT32", "NTFS", "CIFS", "vfat". Please note that "Amahi Greyhole" mounts Amahi shares that will look like "local disk drives" but these are Samba (SMB) mounted shares. An external disk drive will have to be prepared for a Linux/Unix filesystem, in particular ext3. Why? ext3 has been around for sometime, is stable, and "Windows" computers have Open Source drivers available that can be installed to gain access to an ext3 drive.

Prepare an external drive for ext3 as follows:

  • The external USB drive used in this example is a 1 Terabyte (1 TB) Seagate drive.
  • Plug the drive in to a USB connector and power it up.
  • Using a "terminal" session, login in using the "root" user ID.
  • The "device name" of the drive needs to be determined.


Enter the following command:

dmesg

The following information is displayed:

[11122.304178] usb 2-4: new high-speed USB device number 5 using ehci_hcd
[11122.422152] usb 2-4: New USB device found, idVendor=0bc2, idProduct=3320
[11122.422165] usb 2-4: New USB device strings: Mfr=2, Product=3, SerialNumber=1
[11122.422173] usb 2-4: Product: Expansion Desk
[11122.422180] usb 2-4: Manufacturer: Seagate
                    .
                    .
                    .
                    .
                    .
[11123.516813]  sdb: sdb1
  • The "device name" is "sdb1".
  • The USB drive needs to be "unmounted".
umount /dev/sdb1
  • Format drive for ext3 filesystem and set drive label name as "usbdisk".
mkfs -t ext3 -v -L usbdisk /dev/sdb1


Please Note: THIS WILL ERASE ALL DATA ON /dev/sdb1, MAKE SURE THIS IS THE CORRECT USB DRIVE AND NOT ANOTHER DRIVE.

The following information is displayed:

mke2fs 1.42.5 (29-Jul-2012)
fs_types for mke2fs.conf resolution: 'ext3'
Filesystem label=usbdisk
OS type: Linux
                    .
                    .
                    .
                    .
                    .
Writing superblocks and filesystem accounting information: done
  • Whenever a drive is formatted in Linux, about 5% is reserved of the total space on the drive for the operating system to continue using the hard drive to operate, even if it gets full. This is totally unnecessary for a USB external hard drive if it stores only data and not to run an operating system.


Enter the following to remove the reserved space:

tune2fs -m 0 /dev/sdb1

The following information is displayed:

tune2fs 1.42.5 (29-Jul-2012)
Setting reserved blocks percentage to 0% (0 blocks)
  • The external drive is now ready for use.

Mounting an External USB Drive

There are two methods of mounting an external USB drive. The first, mounts the drive automatically each time the server "boots" or "reboots". The second, is mounted manually by the "root" user via the "command-line".

Before proceeding a couple of information items need to be gathered:

  • In the previous section the device name found found via the "dmesg" command. The device name found was "sdb1".
  • We set the set the external drive's "label". It was set to "usbdisk".


To find the label at anytime via the "root" user ID enter:

e2label /dev/sdb1

The following information is displayed:

usbdisk

Both methods of mounting will be controlled by the server's "fstab" configuration file. The fstab (a.k.a. file systems table) file is a system configuration file containing lists of available disks and disk partitions, and indicates how they are to be initialized or otherwise integrated into a system's file system. When the "mount" command is used, the fstab file is read to determine which options should be used when mounting a specified device.

Auto-Mounting

Auto-mount of an external USB drive will occur when a server "boots" or "reboots". Provided the fstab configuration file is properly configured. A powered up USB drive that is plugged in after a server has completed the boot process is not auto-mounted. However, using a "terminal" session with the "root" user ID, and issuing a "mount -a" command will mount an external USB drive.

Configure fstab to auto-mount an external USB drive do the following:

  • Start a "terminal" session login to the "root" user ID.
  • Navigate to the "etc" directory with the "cd" command and make a backup of the current fstab file.
cd /etc
cp /fstab /fstab_bak
  • Using a preferred file editor (i.e. vi, nano), open the fstab file.
fstab
  • Near the bottom of the and after the other fstab entries, add the following:
LABEL=usbdisk        /media/usbdisk       ext3    defaults        0 0
  • Now save the fstab file and exit the editor.
  • Navigate to the /media directory and create a "usbdisk" directory. This is where the external drive will be mounted, this is called a "mount point".
cd /media
mkdir usbdisk
  • Make sure the external drive USB cable is connected to the server and is powered up.
  • Reboot the server.
  • Remember the disk label set earlier when formatting the drive? During the boot process when the "LABEL" is read, this instructs the system to find a hard disk with the label "usbdrive", and then mounts it to the mount point, "/media/usbdisk".

Manual Mounting

Mount of an external USB drive will not occur when a server "boots" or "reboots" when the fstab configuration file is configured for manual mounting. A powered up USB drive that is plugged in after a server has completed the boot process is also not mounted.

Configure fstab for a manual mounting of an external USB drive with the following:

  • Start a "terminal" session login as the "root" user ID.
  • Navigate to the "etc" directory with the "cd" command and make a backup of the current fstab file.
cd /etc
cp /fstab /fstab_bak
  • Using a preferred file editor (i.e. vi, nano), open the fstab file.
nano fstab
  • Near the bottom of the and after the other fstab entries, add the following:
LABEL=usbdisk /media/usbdrive ext3 rw,noauto,users,exec,noatime 0 0
  • Now save the fstab file and exit the editor.
  • Navigate to the /media directory and create a "usbdisk" directory. This is where the external drive will be mounted, this is called a "mount point".
cd /media
mkdir usbdrive
  • Make sure the external drive USB cable is connected to the server and is powered up.
  • Reboot the server.
  • Start a "terminal" session login as the "root" user ID.
  • To manually mount the external drive issue the following command:
mount -L usbdisk
  • The system reads the fstab, when it finds a line entry with the label "usbdrive", it mounts the drive the mount point, "/media/usbdisk".

Unmounting

With both mounting methods the external drive can be unmounted by the following:

  • Start a "terminal" session login as the "root" user ID.
  • Issue the following command to unmount the external drive:
umount /media/usbdrive
  • Should an error occur indicating that the drive is busy and cannot be unmounted enter the command below. Then try the unmount command again.
fuser -km /media

Installing rsnapshot

rsnapshot is available as a package in both the Fedora and Ubuntu Linux distributions. The installation shown here is based on Fedora.

  • Open a "terminal" session and login using the "root" user ID:
yum install rsnapshot
  • Now create the directory structures for storing the backups:
mkdir -p /media/usbdisk/.private/.snapshots
chmod 0700 /media/usbdisk/.private/ 
chmod 0755 /media/usbdisk/.private/.snapshots/

Configuring rsnapshot

This section shows how to configure the rsnapshot.conf configuration file.

  • Open a "terminal" session and login to the "root" user ID.
  • Move to the "/etc" directory.
cd /etc
  • Make a backup copy of the rsnapshot configuration file. Why? So that there is a reference just in case.
cp rsnapshot.conf rsnapshot.conf.bkup
  • Now using a favourite editor, open the "rnapshot.conf" file.


Please Note: Items in the configuration file are separated by "tab" characters and NOT multiple spaces.

nano rsnapshot.conf
  • Find the "SNAPSHOT ROOT DIRECTORY" section and change "snapshot_root" to path where the backups will be stored.
snapshot_root	/media/usbdisk/.private/.snapshots/}}
  • Find the "no_create_root" section and remove the "#". This will allow rsnapshot to create the "snapshot root" directory.
no_create_root  1
  • Find the "BACKUP INTERVALS" section and change the line items. What does this all mean? The "#" character at the beginning of each line means the configuration line item will not be enabled. Remove the "#" character as required. For example, when enabled the "interval daily" line will be active and 7 days of backups will be kept.
interval	   hourly  6 
interval	daily	7
interval	weekly	4
interval	monthly	12
  • Find the "GLOBAL OPTIONS" section. This section defines how much information will be saved in the rsnapshot "log" file.
 The options are:

 Verbose level, 1 through 5.
 1     Quiet           Print fatal errors only
 2     Default         Print errors and warnings only
 3     Verbose         Show equivalent shell commands being executed
 4     Extra Verbose   Show extra verbose information
 5     Debug mode      Everything

Change the following options as required:

verbose         3
loglevel        3
  • Find the "logfile" line and change the line item. After rsnapshot has completed backups this is where the resulting "log" file is stored. Change this line as required.
logfile	/var/log/rsnapshot}}
  • Find the "BACKUP POINTS / SCRIPTS" section. Add changes as seen below. This is the section that defines the "key directories" that will be backed up. Please note the "localhost/", this represents the server that it being backed up. "localhost/" is a default name given to the current server. Change this name as required, say "amahiBox/"?
backup 	/var/hda/files/docs/    	localhost/
backup 	/var/hda/files/pictures/ 	localhost/
backup 	/var/hda/files/movies/  	localhost/
backup 	/var/hda/files/music/   	localhost/
backup 	/var/hda/files/other_shares_you_made	localhost/
  • Save the "rsnapshot.conf" file.

Test the Configuration Changes

  • Now the changes to the rsnapshot configuration file have to be tested. rsnapshot has a feature to test changes to make sure things have been setup correctly.
  • Enter the following on the command-line to initiate the test.
rsnapshot configtest}}
  • When the test completes the following should be displayed:
Syntax OK
  • If an error occurs the rsnapshot configuration file will need to be checked.

Automate Backups

Backups can be automated by creating a "cron job" that can be executed by the system at predetermined intervals.

  • Using a "terminal" session and "root" user ID a "cron job" configuration can be created to perform automated backups.

Create a "cronjobs" text file as follows:

crontab -l > cronjobs
  • Using a favourite text editor open the cronjobs file.
nano cronjobs
  • Add to the cronjobs file for rsnapshot:


0 */4 * * *       /usr/bin/rsnapshot hourly
30 23 * * *       /usr/bin/rsnapshot daily
00 23 * * 1       /usr/bin/rsnapshot weekly
30 22 1 * *       /usr/bin/rsnapshot monthly
  • Save the cronjobs file.
  • Now update the "root" user IDs "crontab" with the following:
crontab cronjobs}}
  • Reboot the server and rsnapshot will be operational.

Email reporting

  • To email a report of backups:
cp /usr/share/doc/rsnapshot*/utils/rsnapreport.pl /root
chmod 744 rsnapreport.pl

* above indicates an rsnapshot version number

  • Add the following to crontab for a weekly email report on rsnapshot:
0 */4 * * *       /usr/bin/rsnapshot hourly 2>&1 | /root/rsnapreport.pl > /root/rsnapreport
00 22 * * 6       /usr/bin/rsnapshot du >> /root/rsnapreport | nail –r "somereturnadress@provider.com" -s"HDA backup report" -S smtp=smtp.yourprovider.com youremail@provider.com < /root/rsnapreport

Please Note: The above information maybe out of date due to technology changes. Please feel to update as required.

Make your backups available on clients (READ ONLY)

If you want to make the backups accesible from your clients:

Create a //hda/backup share in the HDA webinterface

chkconfig nfs --level 2345 on

add a read only NFS export:

nano /etc/exports

add

/media/usbdisk/.private/.snapshots/  127.0.0.1(ro,no_root_squash)

Save file

Unfortunately mounting an NFS share in fstab did not work on my machine after a reboot, so I chose an alternative configuration that mounts the share later in the booting process:

nano /etc/rc.local

Add

mount -r -t nfs localhost:/media/usbdisk/.private/.snapshots/  /var/hda/files/backup/

save file