GithubHelp home page GithubHelp logo

rsyncbtrfs's Introduction

rsyncbtrfs is a small shell script that does incremental backups under linux using rsync on btrfs partitions.

Requirements

You need to have rsync and btrfs-tools installed on your system.

Setup

rsyncbtrfs is a standalone shell script. You can just copy it to a directory in your PATH:

$ mkdir -p ~/bin
$ curl 'https://raw.githubusercontent.com/oxplot/rsyncbtrfs/master/rsyncbtrfs' > ~/bin/rsyncbtrfs
$ chmod a+x ~/bin/rsyncbtrfs

Example

Best way to demo how to use rsyncbtrfs is with an example. Let's say we have a btrfs formatted backup partition mounted under /backup. We want to backup / and /home/joe separately to /backup.

First, we structure the backup partition:

$ mkdir /backup/sys
$ mkdir /backup/joe

Next, we need to initialize each backup directory:

$ rsyncbtrfs init /backup/sys
$ rsyncbtrfs init /backup/joe

All this does is to create an empty file called .rsyncbtrfs under the given directory. rsyncbtrfs backup command aborts if it can't find .rsyncbtrfs file in the destination. Just a safety check.

Time to backup:

$ rsyncbtrfs backup /         /backup/sys --exclude='/home/**'
$ rsyncbtrfs backup /home/joe /backup/joe

Simple enough. Just a note on --exclude option: any argument after the destination is passed onto rsync. Here, we're excluding /home because we don't want to duplicate the backup of /home/joe.

After the backup above, this is what /backup would look like:

$ ls /backup/sys
2014-07-17-13:06:17  cur
$ ls /backup/joe
2014-07-17-14:09:09  cur

The timestamped directories are btrfs subvolumes. cur is a symlink to the latest timestamped subvolume, in this case the only one.

Running the backup again, this is what we get:

$ ls /backup/sys
2014-07-17-13:06:17  2014-07-17-18:31:00  cur
$ ls /backup/joe
2014-07-17-14:09:09  2014-07-17-18:32:11  cur

Notes

rsyncbtrfs creates a new subvolume or snapshots an existing one under a temp directory in destination, named .inprog-XXXXX. It only renames the subvolume to its final timestamped location on success. Same applies to updating of the cur symlink. If the backup fails for any reason, nothing changes in the backup directory. rsyncbtrfs tries to cleanup after itself but worse comes to worst, it might leave the inprog directory behind, which should be cleaned up, although it's not necessary.

You can use --bind-mount argument when backing up to instruct rsyncbtrfs to bind mount the source directory under a temp path. This is useful when you don't want to backup all the mount points under the source:

$ rsyncbtrfs backup --bind-mount / /backup/sys

To take full advantage of btrfs COW functionality, --inplace flag of rsync is used by default. This flag tells rsync to only write the updated data in a file instead of creating a new copy and moving it into place. Using this flag has several (possibly negative) side effects which you should be aware of. Consult rsync's man page for further details.

rsyncbtrfs's People

Contributors

oxplot avatar

Watchers

 avatar

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.