Skip to main content

simple file backup library.

Project description


  • Python 2.7
  • Python 3.4


$ pip install bak


Basic Example


In [1]: !cat test.txt

In [2]: import bak
In [3]: item = bak.Item('test.txt', 'savedir')
# item save as archive in the savedir.(default tar bz2)
# it is same folder with item if savepath is not specified.
In [4]:
In [5]: !ls savedir/

# item does not save if it has no change.
In [6]:
In [7]: !ls savedir/

# if you want save item that has no change, specify force option.
In [8]:
In [9]: !ls savedir/
test.txt.20150321200204.tbz  test.txt.20150321200227.tbz

# confirm backup files as item.archives.
In [10]: item.archives
Out[10]: ['test.txt.20150321200227.tbz', 'test.txt.20150321200204.tbz']


In [11]: !echo 'change!' > test.txt
In [12]: item.restore()
In [13]: !cat test.txt

# Normally, item saves it as current-archive the current item in the same folder.
In [14]: !ls savedir/
test.txt.20150321200204.tbz  test.txt.current.tbz

# item.archives does not contain current-archive.
In [15]: item.archives
Out[15]: ['test.txt.20150321200204.tbz']

# item does not restore if it has no change.
In [16]: item.restore()
In [17]: !ls savedir/
test.txt.20150321200204.tbz  test.txt.current.tbz

In [18]: !rm savedir/test.txt.current.tbz
# if specified refuge_current "false", current-archive does not save.
In [19]: item.restore(force=True, refuge_current=False)
In [20]: !ls savedir/

Rotation Example

This is a sample to delete from the oldest archive.

In [1]: import bak
In [2]: item = bak.Item('test.txt', 'savedir')

# add handler by item.on, specify Signal and Behavior set.
# FillSignal: archive number reaches value specified, execute behavior.
# RemoveBehavior: remove specified index(es) of archive(s).
In [3]: item.on(bak.FillSignal(3), bak.RemoveBehavior(-1))
Out[3]: <test.txt (0)>

In [4]: item.archives
Out[4]: []

In [5]:
In [6]: item.archives
Out[6]: ['test.txt.20150321204308.tbz']

In [7]:
In [8]: item.archives
Out[8]: ['test.txt.20150321204313.tbz', 'test.txt.20150321204308.tbz']

In [9]:
In [10]: item.archives
Out[10]: ['test.txt.20150321204319.tbz', 'test.txt.20150321204313.tbz']



  • Added handler function with the following.

    • Signal(FillSignal, CronSignal, LastTimeSignal)
    • Behavior(RemoveBehavior only)
  • history attribute renamed to archives.


  • There is no change in the file(or directory), it does not save and restore.
  • Added Exceptions.
  • Added Tests.


  • First release.


  • make the reference.
  • add FTP Behavior.
  • provide command.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bak, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size bak-0.2.0.tar.gz (8.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page