{"id":119622,"date":"2020-10-21T08:00:00","date_gmt":"2020-10-21T08:00:00","guid":{"rendered":"https:\/\/fedoramagazine.org\/?p=31944"},"modified":"2020-10-21T08:00:00","modified_gmt":"2020-10-21T08:00:00","slug":"incremental-backup-with-butterfly-backup","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2020\/10\/21\/incremental-backup-with-butterfly-backup\/","title":{"rendered":"Incremental backup with Butterfly Backup"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>This article explains how to make incremental or differential backups, with a catalog available to restore (or export) at the point you want, with <a href=\"https:\/\/matteoguadrini.github.io\/Butterfly-Backup\/\">Butterfly Backup<\/a>.<\/p>\n<p> <span id=\"more-31944\"><\/span> <\/p>\n<h3>Requirements<\/h3>\n<p>Butterfly Backup is a simple wrapper of rsync written in python; the first requirement is <strong><a href=\"https:\/\/fedoramagazine.org\/help-port-python-packages-python-3\/\">python3.3<\/a><\/strong> or higher (plus module <a href=\"https:\/\/cryptography.io\/en\/latest\/\">cryptography<\/a> for <em>init<\/em> action). Other requirements are <strong><a href=\"https:\/\/fedoramagazine.org\/open-source-ssh-clients\/\">openssh<\/a><\/strong> and <strong><a href=\"https:\/\/fedoramagazine.org\/scp-users-migration-guide-to-rsync\/\">rsync<\/a><\/strong> (version 2.5 or higher). Ok, let\u2019s go! <\/p>\n<p>[Editors note: rsync version 3.2.3 is already installed on Fedora 33 systems]<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>sudo dnf<\/strong> install python3 openssh rsync git\n$ <strong>sudo pip3<\/strong> install cryptography<\/pre>\n<h2>Installation<\/h2>\n<p>After that, installing Butterfly Backup is very simple by using the following commands to clone the repository locally, and set up Butterfly Backup for use:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>git<\/strong> clone https:\/\/github.com\/MatteoGuadrini\/Butterfly-Backup.git\n$ <strong>cd<\/strong> Butterfly-Backup\n$ <strong>sudo python3<\/strong> setup.py\n$ <strong>bb<\/strong> --help\n$ <strong>man<\/strong> bb<\/pre>\n<p>To upgrade, you would use the same commands too.<\/p>\n<h2>Example<\/h2>\n<p>Butterfly Backup is a server to client tool and is installed on a server (or workstation). The restore process restores the files into the specified client. This process shares some of the options available to the backup process.<\/p>\n<p>Backups are organized accord to precise catalog; this is an example:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>tree<\/strong> destination\/of\/backup\n.\n\u251c\u2500\u2500 destination\n\u2502 \u251c\u2500\u2500 hostname or ip of the PC under backup\n\u2502 \u2502 \u251c\u2500\u2500 timestamp folder\n\u2502 \u2502 \u2502 \u251c\u2500\u2500 backup folders\n\u2502 \u2502 \u2502 \u251c\u2500\u2500 backup.log\n\u2502 \u2502 \u2502 \u2514\u2500\u2500 restore.log\n\u2502 \u2502 \u251c\u2500\u2500\u2500 general.log\n\u2502 \u2502 \u2514\u2500\u2500\u2500 symlink of last backup\n\u2502\n\u251c\u2500\u2500 export.log\n\u251c\u2500\u2500 backup.list\n\u2514\u2500\u2500 .catalog.cfg<\/pre>\n<p>Butterfly Backup has six main operations, referred to as <strong>actions<\/strong>, you can get information about them with the <em>&#8211;help<\/em> command.<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> --help\nusage: bb [-h] [--verbose] [--log] [--dry-run] [--version] {config,backup,restore,archive,list,export} ... Butterfly Backup optional arguments: -h, --help show this help message and exit --verbose, -v Enable verbosity --log, -l Create a log --dry-run, -N Dry run mode --version, -V Print version action: Valid action {config,backup,restore,archive,list,export} Available actions config Configuration options backup Backup options restore Restore options archive Archive options list List options export Export options<\/pre>\n<h3>Configuration<\/h3>\n<p>Configuration mode is straight forward; If you\u2019re already familiar with the exchange keys and OpenSSH, you probably won\u2019t need it. First, you must create a configuration (rsa keys), for instance:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> config --new\nSUCCESS: New configuration successfully created!<\/pre>\n<p>After creating the configuration, the keys will be installed (copied) on the hosts you want to backup:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> config --deploy host1\nCopying configuration to host1; write the password:\n\/usr\/bin\/ssh-copy-id: INFO: Source of key(s) to be installed: \"\/home\/arthur\/.ssh\/id_rsa.pub\"\n\/usr\/bin\/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed\n\/usr\/bin\/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys\narthur@host1's password: Number of key(s) added: 1 Now try logging into the machine, with: \"ssh 'arthur@host1'\"\nand check to make sure that only the key(s) you wanted were added. SUCCESS: Configuration copied successfully on host1!<\/pre>\n<h3>Backup<\/h3>\n<p>There are two backup modes: <em>single<\/em> and <em>bulk<\/em>.<br \/>The most relevant features of the two backup modes are the parallelism and retention of old backups. See the two parameters <em>&#8211;parallel<\/em> and <em>&#8211;retention<\/em> in the <a href=\"https:\/\/butterfly-backup.readthedocs.io\/en\/latest\/\">documentation<\/a>.<\/p>\n<h4>Single backup<\/h4>\n<p>The backup of a single machine consists in taking the files and folders indicated in the command line, and putting them into the cataloging structure indicated above. In other words, copy all file and folders of a machine into a path.<\/p>\n<p>This is an examples:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> backup --computer host1 --destination \/mnt\/backup --data User Config --type Unix\nStart backup on host1\nSUCCESS: Command rsync -ah --no-links arthur@host1:\/home :\/etc \/mnt\/backup\/host1\/2020_09_19__10_28<\/pre>\n<h4>Bulk backup<\/h4>\n<p>Above all, bulk mode backups share the same options as single mode, with the difference that they accept a file containing a list of hostnames or ips. In this mode backups will performed in parallel (by default 5 machines at a time). Above all, if you want to run fewer or more machines in parallel, specify the <em>&#8211;parallel<\/em> parameter.<\/p>\n<p>Incremental of the previous backup, for instance:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>cat<\/strong> \/home\/arthur\/pclist.txt\nhost1\nhost2\nhost3\n$ <strong>bb<\/strong> backup --list \/home\/arthur\/pclist.txt --destination \/mnt\/backup --data User Config --type Unix\nERROR: The port 22 on host2 is closed!\nERROR: The port 22 on host3 is closed!\nStart backup on host1\nSUCCESS: Command rsync -ahu --no-links --link-dest=\/mnt\/backup\/host1\/2020_09_19__10_28 arthur@host1:\/home :\/etc \/mnt\/backup\/host1\/2020_09_19__10_50<\/pre>\n<p>There are four backup modes, which you specify with the <em>&#8211;mode<\/em> flag: <strong>Full<\/strong> (backup all files) , <strong>Mirror<\/strong> (backup all files in mirror mode), <strong>Differential<\/strong> (is based on the latest <em>Full<\/em> backup) and <strong>Incremental<\/strong> (is based on the latest backup).<br \/>The default mode is <em>Incremental<\/em>; <em>Full<\/em> mode is set by default when the flag is not specified.<\/p>\n<h3>Listing catalog<\/h3>\n<p>The first time you run backup commands, the catalog is created. The catalog is used for future backups and all the restores that are made through Butterfly Backup. To query this catalog use the list command.<br \/>First, let\u2019s query the catalog in our example:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> list --catalog \/mnt\/backup BUTTERFLY BACKUP CATALOG Backup id: aba860b0-9944-11e8-a93f-005056a664e0\nHostname or ip: host1\nTimestamp: 2020-09-19 10:28:12 Backup id: dd6de2f2-9a1e-11e8-82b0-005056a664e0\nHostname or ip: host1\nTimestamp: 2020-09-19 10:50:59<\/pre>\n<p>Press <em>q<\/em> for exit and select a backup-id:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> list --catalog \/mnt\/backup --backup-id dd6de2f2-9a1e-11e8-82b0-005056a664e0\nBackup id: dd6de2f2-9a1e-11e8-82b0-005056a664e0\nHostname or ip: host1\nType: Incremental\nTimestamp: 2020-09-19 10:50:59\nStart: 2020-09-19 10:50:59\nFinish: 2020-09-19 11:43:51\nOS: Unix\nExitCode: 0\nPath: \/mnt\/backup\/host1\/2020_09_19__10_50\nList: backup.log\netc\nhome<\/pre>\n<p>To export the catalog list use it with an external tool like <em>cat<\/em>, include the <em>&#8211;<\/em>&#8211;<em>log<\/em> flag:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> list --catalog \/mnt\/backup --log\n$ <strong>cat<\/strong> \/mnt\/backup\/backup.list<\/pre>\n<h3>Restore<\/h3>\n<p>The restore process is the exact opposite of the backup process. It takes the files from a specific backup and push it to the destination computer.<br \/>This command perform a restore on the same machine of the backup, for instance:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> restore --catalog \/mnt\/backup --backup-id dd6de2f2-9a1e-11e8-82b0-005056a664e0 --computer host1 --log\nWant to do restore path \/mnt\/backup\/host1\/2020_09_19__10_50\/etc? To continue [Y\/N]? y\nWant to do restore path \/mnt\/backup\/host1\/2020_09_19__10_50\/home? To continue [Y\/N]? y\nSUCCESS: Command rsync -ahu -vP --log-file=\/mnt\/backup\/host1\/2020_09_19__10_50\/restore.log \/mnt\/backup\/host1\/2020_09_19__10_50\/etc arthur@host1:\/restore_2020_09_19__10_50\nSUCCESS: Command rsync -ahu -vP --log-file=\/mnt\/backup\/host1\/2020_09_19__10_50\/restore.log \/mnt\/backup\/host1\/2020_09_19__10_50\/home\/* arthur@host1:\/home<\/pre>\n<blockquote class=\"wp-block-quote\">\n<p>Without specifying the \u201c<em>type<\/em>\u201d flag that indicates the operating system on which the data are being retrieved, Butterfly Backup will select it directly from the catalog via the backup-id.<\/p>\n<\/blockquote>\n<h3>Archive old backup<\/h3>\n<p>Archive operations are used to store backups by saving disk space.<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> archive --catalog \/mnt\/backup\/ --days 1 --destination \/mnt\/archive\/ --verbose --log\nINFO: Check archive this backup f65e5afe-9734-11e8-b0bb-005056a664e0. Folder \/mnt\/backup\/host1\/2020_09_18__17_50\nINFO: Check archive this backup 4f2b5f6e-9939-11e8-9ab6-005056a664e0. Folder \/mnt\/backup\/host1\/2020_09_15__07_26\nSUCCESS: Delete \/mnt\/backup\/host1\/2020_09_15__07_26 successfully.\nSUCCESS: Archive \/mnt\/backup\/host1\/2020_09_15__07_26 successfully.\n$ <strong>ls<\/strong> \/mnt\/archive\nhost1\n$ <strong>ls<\/strong> \/mnt\/archive\/host1\n2020_09_15__07_26.zip<\/pre>\n<p>After that, look in the catalog and see that the backup was actually archived:<\/p>\n<pre class=\"wp-block-preformatted\">$ <strong>bb<\/strong> list --catalog \/mnt\/backup\/ -i 4f2b5f6e-9939-11e8-9ab6-005056a664e0\nBackup id: 4f2b5f6e-9939-11e8-9ab6-005056a664e0\nHostname or ip: host1\nType: Incremental\nTimestamp: 2020-09-15 07:26:46\nStart: 2020-09-15 07:26:46\nFinish: 2020-09-15 08:43:45\nOS: Unix\nExitCode: 0\nPath: \/mnt\/backup\/host1\/2020_09_15__07_26\n<em>Archived: True<\/em><\/pre>\n<h2>Conclusion<\/h2>\n<p>Butterfly Backup was born from a very complex need; this tool provides superpowers to rsync, automates the backup and restore process. In addition, the catalog allows you to have a system similar to a &#8220;time machine&#8221;.<\/p>\n<p>In conclusion, Butterfly Backup is a lightweight, versatile, simple and scriptable backup tool.<\/p>\n<p>One more thing; Easter egg: <em><strong>bb<\/strong> -Vv<\/em><\/p>\n<p>Thank you for reading my post.<\/p>\n<p>Full documentation: <a href=\"https:\/\/butterfly-backup.readthedocs.io\/en\/latest\/\">https:\/\/butterfly-backup.readthedocs.io\/<\/a><br \/>Github: <a href=\"https:\/\/github.com\/MatteoGuadrini\/Butterfly-Backup\">https:\/\/github.com\/MatteoGuadrini\/Butterfly-Backup<\/a><\/p>\n<hr class=\"wp-block-separator\" \/>\n<p><em>Photo by <a href=\"https:\/\/unsplash.com\/@leocub?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Manu M<\/a> on <a href=\"https:\/\/unsplash.com\/s\/photos\/butterfly?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Unsplash<\/a><\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction This article explains how to make incremental or differential backups, with a catalog available to restore (or export) at the point you want, with Butterfly Backup. Requirements Butterfly Backup is a simple wrapper of rsync written in python; the first requirement is python3.3 or higher (plus module cryptography for init action). Other requirements are [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[1202,1106,45,61,43,1158,46,47,468,1186,1203,44],"class_list":["post-119622","post","type-post","status-publish","format-standard","hentry","category-fedora-os","tag-archive","tag-backup","tag-fedora","tag-fedora-project-community","tag-for-system-administrators","tag-incremental-backup","tag-magazine","tag-news","tag-python","tag-restore","tag-rsync","tag-using-software"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/119622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=119622"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/119622\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=119622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=119622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=119622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}