Giter Site home page Giter Site logo

snapshotter's Introduction

Hi ๐Ÿ‘‹, I'm Sean

I'm a developer and future Portuguese Water Dog owner currently working for Hypothesis and living in Edinburgh. You can find my blog posts and some of my projects on my site. You can also find me on GitHub Gist, Stack Overflow and Pinboard. If you want to get in touch you can send me an email.

Recent Posts

snapshotter's People

Contributors

funkyfuture avatar glennlagasse avatar lightjohn avatar seanh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

snapshotter's Issues

Bug with destination paths with spaces in them

If the destination path has a space in it, the text before the space seems to get removed when the path is passed to the rsync command. It works if you wrap the path in '...' in zsh though.

Support an option for the maximum space to be used by all snapshots

Run du to figure out how much space all the snapshots use, if it's above a given value delete as many of the oldest snapshots as necessary.

Might also be nice to have a snapshotter du DEST command, print out the actual space used by each *.snapshot dir in DEST, taking hardlinks into account.

Source and destination args not treated the same

It seems to pass rsync a SRC arg like this: 'Mail/' (relative path wrapped in single quotes) but a DST arg like this: /home/seanh/Mail.snapshots (absolute path, not wrapped in quotes). Surely they should be treated the same

Use os to move and remove files and make symlinks

Use Python's standard os module's functions to move and remove files and make symlinks, instead of running mv, rm and ln as subprocesses.

When dealing with a remote destination I think we'll still have to run ssh [user@]host mv|rm|ln ... commands as subprocesses.

Different port ?

Hi,

is there a chance I could make script connect to server on non-default SSH port ?

ty.

`AttributeError` from `snapshotter -h`

~ snapshotter -h
usage: snapshotter [-h] [-n] [--min-snapshots MIN_SNAPSHOTS] SRC DEST

positional arguments:
  SRC                   the path to be backed up
  DEST                  the directory to create snapshots in

optional arguments:
  -h, --help            show this help message and exit
  -n, --dry-run         Perform a trial-run with no changes made (pass the
                        --dry-run option to rsync)
  --min-snapshots MIN_SNAPSHOTS
                        The minimum number of snapshots to leave behind when
                        rolling out old snapshots to make space for new ones
                        (default: 3)
Traceback (most recent call last):
  File "/usr/local/bin/snapshotter", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/snapshotter/snapshotter.py", line 446, in main
    sys.exit(err.output)
AttributeError: 'CommandLineArgumentsError' object has no attribute 'output'

Don't get into a --max-snapshots infinite loop

When --max-snapshots is used and _remove_oldest_snapshot() doesn't actually reduce the number of snapshots reported to _ls_snapshots() (for example when --dry-run is used so that we don't actually run the rm command) then snapshotter gets into an infinite loop as it keeps calling _remove_oldest_snapshot() until _ls_snapshots() reports less than --max-snapshots snapshots, but _ls_snapshots() always reports the same number.

Email on successful/error backup

Hi Sean,

I know crontab can email me about tasks but something more "advanced" would be nice in example:

"Successfully backed up Webserver1" or "Backup of Database1 did not finish with error: not enough disk space on device"

Where Webserver1 and Database1 is actually root@Webserver1 of snapshotter line
A.

Non-standard SSH Port ?

Hi,
Is there any command line to sync to remote server that using a non-standard ssh port? Or is not possible for this version?

Thanks.

Edit:
I tried this command :
snapshotter --rsh='ssh -p 1002' user@host:/path/to/source /path/to/backup

but it keep making trailing / at the end, throwing error:
Bad port '1002/'

Automatically delete old snapshots

If there isn't enough space on the destination volume, automatically delete old snapshots to make enough space.

This is quite complicated:

  • Need to find out how much space the new snapshot requires
  • Need to find out how much space is available on the destination volume (accounting for hard links)
  • Need to find out how much space will be freed by deleting each existing snapshot (accounting for hard links)
  • Need to keep at least one (or a configurable number) of existing snapshots, if enough space can't be freed without leaving at least N existing snapshots intact, then fail

Show progress as snapshots are made

Need to find a way to run a subprocess and gets its exit value, stdout and stderr, while also echoing the stdout and stderr to our stdout and stderr in real-time.

Add configuration file

rsnapshot has a .conf file where one can define paths to backup, snapshotter seems to lack this.

While writing an ansible recipe I realized that I had to write paths in ansible's group variables, which does not allow me to decouple deployment from backup specs :/

@guillermo-carrasco

Attempting to back up to a remote destination generates exception

Trying to execute a snapshot to a remote destination fails with the following exception:

./.local/bin/snapshotter --dry-run /home/glagasse [email protected]:/tank/timemachine/praetorian Traceback (most recent call last): File "./.local/bin/snapshotter", line 9, in <module> load_entry_point('snapshotter==1.0.3', 'console_scripts', 'snapshotter')() File "/home/glagasse/.local/lib/python2.7/site-packages/snapshotter/snapshotter.py", line 480, in main snapshot(*_parse_cli()) File "/home/glagasse/.local/lib/python2.7/site-packages/snapshotter/snapshotter.py", line 400, in snapshot while len(_ls_snapshots(dest)) >= max_snapshots: File "/home/glagasse/.local/lib/python2.7/site-packages/snapshotter/snapshotter.py", line 303, in _ls_snapshots snapshots = [os.path.join(dest, d) for d in os.listdir(dest) OSError: [Errno 2] No such file or directory: '[email protected]:/tank/timemachine/praetorian'

This happens because snapshotter is trying to find the number of remote snapshots in the remote destination using the host machine.
Lines 400-402 is where _ls_snapshots(dest) is called and inside _ls_snapshots it is trying to do a listdir (on the host machine) of the destination which naturally won't exist.

Don't use shell=True

Convert all paths to absolute paths with ~ expanded etc. Run rsync and other executables directly, not via shell.

Fix handling of spaces in remote and local source and destination paths

I think source and destination paths may be treated differently, and remote and local paths are certainly treated differently. For example os.path.abspath(os.path.expanduser(path)) is called on local paths but not on remote ones, and this seems to change \ to \\.

This makes a difference when paths have spaces in them - whether you need to backslash-escape the spaces, quote the path, or both. Currently what you need to do depends on whether it's a local or remote path.

Multiple --link-dest arguments?

Currently files in a new snapshot will only be hard-linked to existing files in the latest snapshot. Find all existing snapshot directories in the target directory and pass rsync a --link-dest argument for each of them.

Handle "no space left on device" by deleting old snapshots

It might be better to figure out before running rsync how much space the new snapshot will need. But failing that: detect "no space left on device" errors from rsync, delete the oldest snapshot, repeat. Fail if the number of remaining snapshots reaches a threshold.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.