Package: b2restore
B2RESTOREb2restoreis a command line
utility which can be used withrcloneto
manually restore aBackblaze B2archive
for any given date and time. Alternatively, you can create a git
repository of all date and time snapshots (subject to thelimitationsdescribed below).InstallationArch users can installb2restore from the
AUR.Python 3.7 or later is required. Noteb2restore is on
PyPIso just ensure thatpython-pipxis installed then type the
following to install:$pipxinstallb2restoreTo upgrade:$pipxupgradeb2restoreTo remove:$pipxuninstallb2restoreCreation of initial rclone copyThis utility is typically used withrclone.
Simplyrclone syncorrclone copythe B2 bucket or sub-paths from
the bucket which you want to restore. YouMUSTspecify--b2-versionsto include all file versions, e.g:rclone sync --b2-versions --fast-list B2:mybucket b2filesThe above command will copy all files and available versions to the
createdb2filesdirectory. You only need to do this once.Creation of snapshot at given timeGiven the abovercloneinitial copy, you run this utility to
create a snapshot of the directory tree for the time you are interested
in.E.g. to recreate the tree of latest files, inoutdir:b2restore b2files outdirE.g. to recreate the tree of files at a specified time:b2restore -t 2018-01-01T09:10.00 b2files outdirJust keep selecting different times to incrementally recreateoutdiras it existed at that time. The utility prints a line for each file
updated, created, or deleted inoutdircompared to the previous
contents. The date and time of each updated/created/deleted file is also
listed. The target files are all hard-linked from the files in the
source directory so theoutdirtree is created very quickly since
files do not need to be actually copied. Thus you can conveniently
experiment with the time string to quickly see file differences.Rather than specifying an explicit time string using-t/--time, you
can instead choose to use-f/--filetimeto specify any one specific
file's modification time at which to recreate the target tree of files.You may wish to manuallygit commiteach snapshot you create in the
outdir tree between your manually time-selected runs. If so, you will
need to add the-gswitch to preventb2restorefrom deleting your
top level.git/repo on each run.Note that this utility does not recreate empty directory hierarchies.
All empty directories in the target tree are deleted.LimitationsIf you want to restore a snapshot of your files for a specific
date/time, then unfortunately the metadata returned byrclonefromBackblaze
B2is not sufficient to create a
completely legitimate snapshot. However, all files restored for a
specific date/time will contain correct contents, the only issue is that
there may be some files which were actually deleted by that date but
those files may still be present. An example best illustrates the issue:Say you run a rclone backup every night at 0000 am to B2:mybucket.On 01-Jan you create a filea.txt.On 02-Jan you delete filea.txt.On 03-Jan you create filea.txtagain (but with different content to 01-Jan).On 04-Jan you retrieve the latest archive usingrclone sync --b2-versions --fast-list B2:mybucket b2files.If you runb2restore b2files outdirthen you will get the latest
03-Jan version ofa.txtinoutdir. If you then runb2restore -t<time> b2files outdirfor 01-Jan, then you will geta.txtwith the correct
content from 01-Jan. However, if run that command for 02-Jan, then you
will still see thea.txtfile and content corresponding to 01-Jan
(when it actually should be deleted for that day). If you are only using
b2restore to find and restore one or more files for specific date/times, then
this is not a serious practical problem. There may be some extra files
around, but all files are correct for the specified date/time.Command line optionsusage: b2restore [-h] [-t TIME | -f FILETIME] [-s] [-g] [-p PATH]
                 indir [outdir]

Program to recreate Backblaze B2 file archive at specified date and time.

positional arguments:
  indir                 input B2 archive containing all file versions (from
                        --b2-versions)
  outdir                output directory to recreate for given time

options:
  -h, --help            show this help message and exit
  -t TIME, --time TIME  set time YYYY-MM-DD[THH:MM[.SS]], default=latest
  -f FILETIME, --filetime FILETIME
                        set time based on specified file
  -s, --summary         just print a summary of files and versions
  -g, --gitkeep         preserve any top level git dir in outdir
  -p PATH, --path PATH  only process files under given pathCreation of git repository of all snapshotsRather than runb2restorefor the given date + times you are
interested in, you can instead choose to run the providedb2restore-create-gitutility to automatically create a git repository
of snapshots of files for all the dates + times inherent in thercloneinitial copy.So after performing thercloneinitial copy above, run the following
command to create a complete git repository:b2restore-create-git b2files outdirThencd outdirand rungit logetc to view the history.b2restore-create-git command line optionsUsage: b2restore-create-git [-options] indir outdir
Create git repository from given B2 rclone copy.
Options:
-t YYYY-MM-DDTHH:MM.SS (start git repo from given time)
-e YYYY-MM-DDTHH:MM.SS (end git repo before given time)
-p (only process files under given path)Test run utilityA command line utilityb2restore-create-dummy-filesis included to
facilitate testingb2restoreon your restored file tree without
actually downloading any files from your B2 archive(!). This utility
parsesrclone lsloutput to recreate your B2 bucket directory and
hierarchy of file versions. Only the file names are recreated of course,
the file contents are set to their actual byte size but with random byte
contents (or zero filled if you specify-z, or to zero length if you
specify-s).This utility requires almost nothing to download from your B2 archive
and runs extremely quickly. You can then runb2restoreagainst this
dummy archive to simulate what files are changed between versions, etc.
It is also good to get a feel for howb2restoreworks, what it does,
and whether it suits your needs without requiring you to first perform
an onerous huge download of your entire B2 archive.Here is an example usage:rclone lsl --b2-versions B2:mybucket | b2restore-create-dummy-files b2files
b2restore b2files outdir
du -shl outdir # (see how much storage tree of latest versions uses)
b2restore -t 2018-05-10T12:00.00 b2files outdir
du -shl outdir # (see how much storage tree of yesterdays versions uses)b2restore-create-dummy-files command line optionsUsage: b2restore-create-dummy-files [-options] outdir
Reads B2 file list (from lsl output) from standard input to create
dummy tree of files.
Options:
-z (zero fill files, not with random content which is default)
-s (set files to zero length, not their actual size)
-p (only process files under given path)LicenseCopyright (C) 2018 Mark Blakeney. This program is distributed under the
terms of the GNU General Public License.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or any later
version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License athttp://www.gnu.org/licenses/for more details.