Skip to content

mmahnic/py-findjob

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

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
    ])

About

Simple incremental backups with Python, find and zip

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages