Package: cobra-archiver
CoBRA - Comprehensive Backing up and Restoration ArchiverCobra is a tool for creating, managing and restoring backups.
It is designed to cover docker powered applications as well as it allows backing up of
regular file system folders.How to usepip install cobra-archiverCLIAfter thatcobracommand will be available from the command line.To get the cli description please issuecobra --helpor
e.g.cobra backup --helpto get help on certain command.This will backup all the docker volumes as well as/want/this/dir/backed/updirectory, butskip-this-volumeand-this-one.cobrabackupbuild--push--dir/want/this/dir/backed/up\--creds/path/to/google-service-acc-key.json--folder-idgoogle-drive-folder-id\--excludeskip-this-volumeand-this-oneThis restores latest backup from the given remote folder.cobrabackuppull--latest--restore\--creds/path/to/google-service-acc-key.json--folder-idgoogle-drive-folder-idRemote storageFor now Google Drive only supported. If you find this project useful you can contribute
to enhance it. Or at least you can post a feature request.To have this work theGoogle Service Accountis necessary.
The service account id (email) looks like<the-name-you-choose>@hip-heading-376120.iam.gserviceaccount.com.Under the service account you've created add the key pair and download it in.jsonformat.Now create the folder within your Google Drive you wish to push the backups in.Share this folder with the service account (email) from step 1.HooksThey are listed below.HOOKS=('before_build','after_build','before_push','after_push','before_pull','after_pull','before_restore','after_restore')One can either issuecobra hooks initthat populates hook files to the default directory.
Or put the hook files with the names e.g.before_build.pyorbefore_build.sh.
For shell scriptchmod +x before_build.shis necessary.Cobra searches for.pyfile first if found imports it and executehookfunction as.hook(hook_name=hook_name,hooks_dir=hooks_dir,backup_dir=backup_dir,filename=backup_filename,docker=docker_client)hook_nameis the one from the list abovehooks_dirthe directory where hooks residebackup_dirthe local backup directory where backup is storedfilenamethe backup file namedockerDockerClientobjectIf.pyfile is not found. The default hook is called that continue searching for.shfile.
If latter found it's called viasubprocess.check_call(). With the same params exceptdocker.By defaultcobracopies and packs the content of a volume.
To backup database with tools likemongodumporpg_dumpone may usebefore_buildhook
and--exclude volume-namefrom the processing.before_buildhook may look like this in such a case.#!/usr/bin/env bash# Stop any containers that mangle database while dumping to have consistent dumpdockerstopmy-excellent-appMONGO_DUMP_DIR=/tmp/mongodump
mkdir-p"${MONGO_DUMP_DIR}"mongodump--archive="${MONGO_DUMP_DIR}/mongo-dump-by-hook.tar.gz"--db=test--gzipmongodb://mongo-container-name:27017# Then start them againdockerstartmy-excellent-appErrors that are propagated from hooks stop farther processing.
To see more details please inspect e2e test sources.Default locationsTo find out paths used by cobra one can issue following.
On my system I have this output.$cobradirs/home/q/.local/share/cobra/backup
/home/q/.cache/cobra
/home/q/.local/share/cobra/hooksPythonMinimum python version is 3.7.fromcobra.apiimportApifromcobra.hooksimportHooksfromdockerimportDockerClientapi=Api(gateway=DockerClient(),hooks=Hooks())api.backup_build()Method parameters are described in cli helpcobra backup --helpe.g.Security noticeThis code is subject to command injection vulnerabilty. There are no such a checks.
The caller should provide all checks on his own.Run testsgitclonehttps://github.com/yell0w4x/cobra.gitcdcobra
./run-tests--unitThe above runs unit tests. To execute end-to-end tests run is as follows.
Note that docker must reside in the system.
To install it on Ubuntu usewget -qO- https://get.docker.com | sudo bash.
On Manjaro (Arch) issuesudo pacman -S docker../run-tests--e2e--folder-idgoolge-drive-folder-id--keypath/to/google-service-account-key.jsonorGOOGLE_DRIVE_FOLDER_ID=goolge-drive-folder-idGOOGLE_SERVICE_ACC_KEY=path/to/key.json./run-tests--e2eThe tests are based on pytest. All the extra arguments are passed to pytest.
E.g. to have verbose output use-vor-vv. To show stdout-s.
To run certain tests use-k test_nameand etc. For details see the pytest docs../run-tests --help
Run cobra unit and e2e tests.

Usage:
    ./run-tests [OPTIONS] [EXTRA_ARGS]

All the EXTRA_ARGS are passed to pytest

Options:
    --help                Show help message
    --unit                Run unit tests
    --e2e                 Run e2e tests
    --skip-build          Skip building dist files
    --folder-id FOLDER_ID Google drive folder id to use as remote storage for e2e tests. 
                          If not given read from GOOGLE_DRIVE_FOLDER_ID environment variable.
    --key KEY_FN          Path to google service account key file in json format
                          If not given read from GOOGLE_SERVICE_ACC_KEY environment variable.