Simple incremental backups with Python, find and zip
Python
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.mkd
findjob.py

README.mkd

Simple incremental backups with Python, find and zip

findjob.py

A module for backup systems that incrementally add files to ZIP archives. The library uses external programs find and zip to do the work. The classes in findjob.py are used to prepare the parameters for the external programs and to run them.

Backup parameters are defined in Python scripts that use the module. In the example below the files from the ~/Documents folder are archived. Some directories and files are excluded from archiving (skipDirs, skipFiles).

Additional settings can be placed in .backupsettings files in the directories that are traversed by the jobs. ATM the only supported settings in these files are 'skipfiles=' and 'skipdirs=':

skipfiles=*.build:*.out:*.temp
skipdirs=tempdir:builddir

With the default archive manager settings the archived files for each week are placed in

OUT_ROOT/<year>/w/documents<year>w<week><suffix>.zip

and the monthly archives are created in

OUT_ROOT/<year>/m/documents<year>m<month><suffix>.zip

Here is an example backup script:

from findjob import FindJobBuilder, ArchiveFileManager, BackupModeSelector
import os

PROFILE="/home/user"

tmpdirs    = "*/xdata:*/xtemp:*/temp:*/Temp:*/tmp"
builddirs  = "*/BUILD:*/Build:*/build"
backupdirs = "*/.backup:*/.xbackup"

OUT_ROOT   = "/home/user/.backup"
skipdirs   = tmpdirs
inclfiles  = "*:.*"
exclfiles  = "*.stackdump"

MODE_SELECTOR = BackupModeSelector()

# Define a backup job
def backup_documents(arch):
    global PROFILE, MODE_SELECTOR
    global tmpdirs, builddirs, backupdirs

    arch.configureBackup("documents", "w", incremental=True, selector=MODE_SELECTOR)

    bdir = os.path.join(PROFILE, "Documents")
    find = FindJobBuilder(bdir)
    find.includeFiles("*:.*")
    find.skipDirs([tmpdirs, builddirs, backupdirs])
    find.skipFiles("*.obj:*.war:*.ncb:*.stackdump:*/bin/*.o")

    arch.findAndZip(find)

arch = ArchiveFileManager(OUT_ROOT)
arch.runBackups([
    backup_documents
    # add more jobs
    ])