This script operates HAMMER PFSes and dumps its contents for backup purposes.
It uses mirror-read directive (see ‘man 8 hammer’) to perform a dump to stdout that is redirected to a file with or without compression.
It can take two types of backup:
Full: Where ALL the data of the PFS is sent to a file.
Inremental: It requires a previous full backup.
Additionally to the backup data itself, it creates a .bkp file which contains metadata relative to the full and/or incremental
backups. The format is the following:
filename,rsv01,rsv02,backup type,shared uuid,last TID,md5 hashfilename : Backup data file file.
rsv01,rsv02: Reserved fields
backup type: 1 or 2(full or incremental, respectively)shared uuid: PFS shared UUID for mirror ops
last TID : Last transaction ID. Next incr. backup starting TID
md5 hash : For restoring purposes
> head -1 20140305222026_pfs_t1_full.xz.bkp
How to use it?
$ hammer-backup -h
Usage: hammer-backup.sh [-h][-l][-v][-i <full-backup-file>][-f][-c <compress-rate>] -d [<backup-dir>] <path-to-PFS>
-h: Help outputo above.
-i <full-backup-file>: Incremental backup. Needs the full backup metadata file.
Relative path to -d. You can specify 'auto' and the
script should determine what's the latest full backup.
-f: Full backup
-c: Compress rate for xz(1) -d: Backup directory
-l: List backups from backup directory.
-k: Validates integrity of all backup files.
<path-to-PFS>: PFS path to backup
Mirror-write the files in the correct order. First the full, then the
incremental ones. NOTE: -y on the hammer command will actually create
a slave PFS.
$ unxz -c /root/backups/20140308001146_pfs_var.xz | hammer -y mirror-write /pfs/var_2
PFS slave /pfs/var_2 does not exist. Auto create new slave PFS!
Creating PFS #10 succeeded!/pfs/var_2
operating as a SLAVE
snapshots directory defaults to /var/hammer/<pfs>
Source can update synctid to 0x000000011db6dc20
Next, incremental ones:
$ unxz -c /root/backups/20140308002450_pfs_var.xz | hammer -y mirror-write /pfs/var_2
Source can update synctid to 0x000000011db6e440
Once done, you can just upgrade the /pfs/var_2
$ hammer pfs-upgrade /pfs/var_2
pfs-upgrade of PFS#10 () succeeded
For the example we used you have to make sure no process is using the current /var PFS, and if none is you can just go ahead and unmount it.
Afterwards you can modify the symbolic link in /pfs to point to the restored one as needed.
You can upload the .xz files and the .bkp files whenever you want, for example a remote FTP server.