What is HotCopy
(Description taken from the R1Soft website)
R1Soft Hot Copy (hcp) is the answer to taking online point-in-time disk and volume snapshots in Linux. Use the hcp command line utility to take an instant snapshot of any mounted file system on almost any block device.
· Add point-in-time open file backups to your existing backup scripts for free e.g. tar and rsync
· Check your disk for errors with fsck without rebooting and without unmounting your file system!
· Test scripts and programs in an instant snapshot of your live environment before you use them on real data
· Keep instantly recoverable snapshots available by taking periodic snapshots via cron
Installation
This document will assume the Operating System this tool will be installed to is a 64-bit OS. At the time this document was created HotCopy was at version 3.6.1.
There are two components needed for install.
1. r1soft-hotcopy-3.6.1.x86_64.rpm
2. r1soft-setup-3.6.1.x86_64.rpm
The first package is the HotCopy utility. The second package is the setup utility to get and install the kernel driver.
r1soft-hotcopy-3.6.1.x86_64.rpm
To install this package you need to be root. Copy the packages to the server’s /tmp directory.
# cd /tmp
# rpm -ivh r1soft-hotcopy-3.6.1.x86_64.rpm
r1soft-setup-3.6.1.x86_64.rpm
To install this package you need to be root. Copy the packages to the server’s /tmp directory.
# cd /tmp
# rpm -ivh r1soft-setup-3.6.1.x86_64.rpm
Setup
Now that the packages are installed you need to download and install the Kernel driver. Your server will need access to the Internet to perform the following command.
As a root user run the following command and you should see the following output.
# /usr/sbin/hcp-setup --get-module
Checking for binary module
Waiting
Complete.
Saving kernel module to ‘/lib/modules/r1soft/hcpdriver-cki-2.6.18-194.17.4.el5.ko’
#
Usage
Creating a Snapshot
Verify the filesystem you want to snapshot.
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 7.8G 3.4G 4.0G 47% /
/dev/sda1 99M 19M 75M 21% /boot
Tmpfs 1006M 0 1006M 0% /dev/shm
Create the snapshot
Verify the Snapshot Exists
Example of “foo”
In this example we’ll “accidentally” delete a file in the /tmp directory but be able to retrieve it from the snapshot.
Good thing I took a snapshot before I began messing around. I will now retrieve the file from the snapshot.
We’re back! File has been retrieved. Disaster averted.
Removing a Snapshot
Additional Cool Things
You can have the Snapshot created and mounted to a completely different filesystem.
Why would you want to do that?
Backups of course. Let’s assume we have a system that can have very little downtime and cannot be backed up while its special application is running. Backups take 2 or 3 hours and that kind of downtime in not acceptable. Here is what we would do (assuming there is a separate disk to snap to)
1. Bring down the application
2. Create a Snap of the filesystem to another disk. This process takes a second or two.
3. Bring the application up
4. Take a backup of the Snap instead of the live filesystem.
Your application would be down only for a matter of seconds and backing up the Snap would not affect disk I/O on production filesystem.
Example:
Verify the New Disk is Seen
[root@centos55-test /]# fdisk -lu /dev/sdb
Disk /dev/sdb: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders, total 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
Partition the Disk
[root@centos55-test /]# fdisk /dev/sdb
The number of cylinders for this disk is set to 1566.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): u
Changing display/entry units to sectors
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (63-25165823, default 63):
Using default value 63
Last sector or +size or +sizeM or +sizeK (63-25165823, default 25165823):
Using default value 25165823
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Create a Linux FileSystem on the New Partition
[root@centos55-test /]# mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1572864 inodes, 3145720 blocks
157286 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3221225472
96 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Create a Directory to Mount the New Filesystem to
[root@centos55-test /]# mkdir -p /mnt/bkup
Mount it
[root@centos55-test /]# mount /dev/sdb1 /mnt/bkup
Verify it is Mounted
[root@centos55-test /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.8G 3.4G 4.1G 46% /
/dev/sda1 99M 19M 75M 21% /boot
tmpfs 1006M 0 1006M 0% /dev/shm
/dev/sdb1 12G 159M 12G 2% /mnt/bkup
Stop Application or Database
Do what is needed to stop the application or database
Create a Snapshot of the FileSystem we want to backup
-m and -c
This takes all “additional” I/O off of the production filesystem
[root@centos55-test /]# hcp -m /mnt/bkup -c /dev/sdb1 /dev/mapper/VolGroup00-LogVol00
R1Soft Hot Copy 3.6.1 build 10439 (http://www.r1soft.com)
Documentation http://wiki.r1soft.com
Forums http://forum.r1soft.com
Thank you for using Hot Copy!
R1Soft makes the only Continuous Data Protection software for Linux.
Starting Hot Copy: /dev/mapper/VolGroup00-LogVol00.
Changed blocks stored: /dev/sdb1
Snapshot completed: 0.001 seconds
File system frozen: 0.128 seconds
Hot Copy created: Fri Oct 15:12:05 CDT 2010
Creating Hot Copy snapshot device: /dev/hcp1, Please Wait...
Hot Copy created at: /dev/hcp1
Mounting /dev/hcp1 read-write
Hot Copy mounted at: /mnt/bkup
[root@centos55-test /]#
Start Application or Database again
Do what is need to start the DB or APP again
Verify the Snap has been made and mounted.
[root@centos55-test /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.8G 3.4G 4.1G 46% /
/dev/sda1 99M 19M 75M 21% /boot
tmpfs 1006M 0 1006M 0% /dev/shm
/dev/sdb1 7.8G 3.4G 4.1G 46% /mnt/bkup
/dev/hcp1 7.8G 3.4G 4.1G 46% /mnt/bkup
[root@centos55-test /]#
Run the backup on the Snap
Run Backup Against /mnt/bkup
Once the backup is complete you can remove the Snap
[root@centos55-test /]# hcp -r /dev/hcp1
R1Soft Hot Copy 3.6.1 build 10439 (http://www.r1soft.com)
Documentation http://wiki.r1soft.com
Forums http://forum.r1soft.com
Thank you for using Hot Copy!
R1Soft makes the only Continuous Data Protection software for Linux.
Hot Copy Session has successfully been stopped.
All active Hot Copy sessions have been stopped. It is now safe to restart the R1Soft Backup Agent.
[root@centos55-test /]#