суббота, 31 августа 2013 г.

Automated differential backup using 7zip for linux/windows

There are a lot of ways of doing differential backups, tons of software, freeware of shareware. I want to share one I didn't know about which I liked very much. It is unfair so little information can be found the Net about 7-zip archival tool, which can handle differential backups with ease.  Article is for CLI geeks, who understands where to push these commands )

What are Differential and Incremental backups?

Incremental backup

is a backup method in which multiple backups are kept (not just the last one). These backups will be incremental if each original piece of backed up information is stored only once, and then successive backups contain only the information that changed since a previous backup.

Differential backup

is a cumulative backup of all changes made since the last full or normal backup, i.e., the differences since the last full backup
I am talking about Differential backup, which contains one FULL archive and several DIFFERENTIAL archives on different date each.

Using 7zip for automated backup

Is really great tool for archiving files. Linux and win32 platform support, crossplaform archiving, multi threading support.

7zip installation

  1. Windows, download
  2. Ubuntu: aptitude install p7zip

7zip commands to create a backup of files

First step is to create full backup which is fairly easy:
7za a c:\archive.7z  c:\folder_to_archive
Next is to create differential backup with name diff1.7z
7za u c:\archive.7z  c:\folder_to_archive  -ms=off -mx=9 -t7z -u- -up0q3r2x2y2z0w2!c:\diff1.7z
  • Where command switches stand for:
  • -mx=9 - best compression
  • -t7z - 7z archive type
Wtf "-up0q3r2x2y2z0w2!c:\diff1.7z" is ?
Actions mask to determinite 7z behavior
p - File exists in archive, but is not matched with wildcard.
q - File exists in archive, but doesn't exist on disk.
r - File doesn't exist in archive, but exists on disk.
x - File in archive is newer than the file on disk.
y - File in archive is older than the file on disk.
z - File in archive is same as the file on disk
w - Can not be detected what file is newer (times are the same, sizes are different)
Number means action:
0 Ignore file (don't create item in new archive for this file)

1 Copy file (copy from old archive to new)

2 Compress (compress file from disk to new archive)

3 Create Anti-item (item that will delete file or directory during extracting). This feature is supported only in 7z format
More detailes on this switch here:

How to extract files from 7zip differential backup

First step is to extract full backup  archive:
7za.exe x c:\archive.7z -oc:\recovery_path\
Next,  to extract needed differential  backup on top to the same folder
7za.exe x c:\archive.7z -aoa -y -oc:\recovery_path\
-aoa Overwrite All existing files without prompt.
-y (assume Yes on all queries) switch
After extraction destination folder will contain exact structure and files on date of backup!

What is 7zip anti-item

When creating differential archive 7zip matches files that have been deleted and creates anti-file entry which tells 7zip extractor actually do delete file when overriding master archive. Thats why resulting recovery folder will look the same as on archiving stage.

7zip backup limitations

DO NOT USE the 7-zip format on Linux/Unix  for system backup purposes, because of 7zip does not store the owner/group of the file.
On Linux/Unix, in order to backup directories you should use tar
to backup a directory
tar cf – directory | 7za a -si directory.tar.7z
to restore your backup :
7za x -so directory.tar.7z | tar

Комментариев нет: