{"id":16863801,"url":"https://github.com/nazar-pc/just-backup-btrfs","last_synced_at":"2025-03-17T05:32:36.547Z","repository":{"id":23535551,"uuid":"26902322","full_name":"nazar-pc/just-backup-btrfs","owner":"nazar-pc","description":"Script that does just that - creates backups using snapshot of btrfs filesystem. Also it makes rotation of snapshots by removing old ones and keeping as many snapshots as you want.","archived":false,"fork":false,"pushed_at":"2024-06-24T20:05:51.000Z","size":35,"stargazers_count":28,"open_issues_count":2,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-15T15:18:06.670Z","etag":null,"topics":["backup","btrfs","cli","snapshot","subvolume"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nazar-pc.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-20T08:10:56.000Z","updated_at":"2024-06-24T20:05:54.000Z","dependencies_parsed_at":"2024-10-19T00:14:31.250Z","dependency_job_id":"c05d70c5-86dc-4978-8b3a-d8589d5d69ad","html_url":"https://github.com/nazar-pc/just-backup-btrfs","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"ca4a7adac87bf3089c7e872b619fa208ac579cf1"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazar-pc%2Fjust-backup-btrfs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazar-pc%2Fjust-backup-btrfs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazar-pc%2Fjust-backup-btrfs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nazar-pc%2Fjust-backup-btrfs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nazar-pc","download_url":"https://codeload.github.com/nazar-pc/just-backup-btrfs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243846984,"owners_count":20357297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backup","btrfs","cli","snapshot","subvolume"],"created_at":"2024-10-13T14:39:47.317Z","updated_at":"2025-03-17T05:32:34.787Z","avatar_url":"https://github.com/nazar-pc.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Just backup btrfs\nScript that does just that - creates backups using snapshot of btrfs filesystem. Also it makes rotation of snapshots by removing old ones and keeping as many snapshots as you want.\n\n\n### Why?\nI wanted simple thing: store snapshots of several subvolumes in one place and keep specific number of snapshots for each time interval (more recent and less elder snapshots).\n\nI was wondered that no existing solutions fit my needs, so I decided to write it:)\n\n### Requirements\n* php-cli (version 5.4+)\n* php-sqlite3\n\nYou can get them both on Ubuntu 15.10-:\n```bash\nsudo apt-get install php5-cli php5-sqlite\n```\nUbuntu 16.04+:\n```bash\nsudo apt-get install php-cli php-sqlite3\n```\n\nAlso enable sqlite3 extension since it may be disabled by default.\nUbuntu 15.10-:\n```bash\nsudo php5enmod sqlite3\n```\nUbuntu 16.04+\n```bash\nsudo phpenmod sqlite3\n```\n\n### Installation\nThe whole thing is a single file, so first way is just to copy file `just-backup-btrfs` somewhere.\n\nAlternatively you can install it globally using Composer like this:\n```bash\nsudo COMPOSER_BIN_DIR=/usr/local/bin composer global require nazar-pc/just-backup-btrfs\n```\n`COMPOSER_BIN_DIR=/usr/local/bin` will instruct Composer to install binary to `/usr/local/bin` so that you'll be able to call `just-backup-btrfs` right after installation.\nAlternatively you can skip it and add `~/.composer/vendor/bin/` to your PATH.\n\n### Removal\nIf installed manually - just remove file, if installed with Composer - remove it with:\n```bash\nsudo COMPOSER_BIN_DIR=/usr/local/bin composer global remove nazar-pc/just-backup-btrfs\n```\nOr without `COMPOSER_BIN_DIR=/usr/local/bin` if you didn't use it during installation.\n\n### Usage\nScript expects configuration file to be present at location `/etc/just-backup-btrfs.json`, example of such file you can find below. Also, if you want to use other path to config file - specify it as argument.\n\nThere are few ways to run script.\n```bash\nsudo php just-backup-btrfs\n```\n\nor mark file as executable and just\n```bash\nsudo ./just-backup-btrfs\n```\n\nor mark as executable and put into `/etc/cron.daily` to make backups every day.\n\nWith custom path to config file:\n```bash\nsudo ./just-backup-btrfs /path/to/config.json\n```\n\nOutput will be like this:\n```\nJust backup btrfs started...\nCMD: /bin/btrfs subvolume snapshot -r \"/\" \"/backup/root/2016-03-12_16:29:52\"\nCMD: sync\nSnapshot 2016-03-12_16:29:52 for / created successfully\nCMD: mount\nMounting root subvolume skipped, since already mounted\nMaking incremental backup\nCMD: /bin/btrfs send -p \"/backup/root/2016-03-12_16:26:48\" \"/backup/root/2016-03-12_16:29:52\" | /bin/btrfs receive /tmp/just_backup_btrfs_45e177f34dddc33a5b1537ce8f4913ba/root\nAt subvol /backup/root/2016-03-12_16:29:52\nCMD: /bin/btrfs subvolume delete \"/backup_hdd/root/2016-03-11_16:30:01\"\nOld snapshot 2016-03-11_16:30:01 removed successfully from /backup_hdd/root\nCreating incremental backup 2016-03-12_16:29:52 of / to /backup_hdd/root finished successfully\nUnmounting root subvolume skipped\nCMD: /bin/btrfs subvolume delete \"/backup/root/2016-03-12_15:30:01\"\nOld snapshot 2016-03-12_15:30:01 removed successfully from /backup/root\nCMD: /bin/btrfs subvolume snapshot -r \"/home\" \"/backup/home/2016-03-12_16:30:04\"\nCMD: sync\nSnapshot 2016-03-12_16:30:04 for /home created successfully\nCMD: mount\nMounting root subvolume skipped, since already mounted\nMaking incremental backup\nCMD: /bin/btrfs send -p \"/backup/home/2016-03-12_16:26:51\" \"/backup/home/2016-03-12_16:30:04\" | /bin/btrfs receive /tmp/just_backup_btrfs_45e177f34dddc33a5b1537ce8f4913ba/home\nAt subvol /backup/home/2016-03-12_16:30:04\nCMD: /bin/btrfs subvolume delete \"/backup_hdd/home/2016-03-11_16:30:08\"\nOld snapshot 2016-03-11_16:30:08 removed successfully from /backup_hdd/home\nCreating incremental backup 2016-03-12_16:30:04 of /home to /backup_hdd/home finished successfully\nUnmounting root subvolume skipped\nCMD: /bin/btrfs subvolume delete \"/backup/home/2016-03-12_15:30:05\"\nOld snapshot 2016-03-12_15:30:05 removed successfully from /backup/home\nCMD: /bin/btrfs subvolume snapshot -r \"/web\" \"/backup/web/2016-03-12_16:30:30\"\nCMD: sync\nSnapshot 2016-03-12_16:30:30 for /web created successfully\nCMD: mount\nMounting root subvolume skipped, since already mounted\nMaking incremental backup\nCMD: /bin/btrfs send -p \"/backup/web/2016-03-12_16:26:58\" \"/backup/web/2016-03-12_16:30:30\" | /bin/btrfs receive /tmp/just_backup_btrfs_45e177f34dddc33a5b1537ce8f4913ba/web\nAt subvol /backup/web/2016-03-12_16:30:30\nCMD: /bin/btrfs subvolume delete \"/backup_hdd/web/2016-03-11_16:30:26\"\nOld snapshot 2016-03-11_16:30:26 removed successfully from /backup_hdd/web\nCreating incremental backup 2016-03-12_16:30:30 of /web to /backup_hdd/web finished successfully\nUnmounting root subvolume skipped\nCMD: /bin/btrfs subvolume delete \"/backup/web/2016-03-12_15:30:15\"\nOld snapshot 2016-03-12_15:30:15 removed successfully from /backup/web\nJust backup btrfs finished!\n```\n\nAlso you can call it with cron or in some other way:)\n\n### What it actually does?\n* reads configuration from `/etc/just-backup-btrfs.json`\n* creates `destination_within_partition/history.db` SQLite database if it doesn't exists yet\n* creates snapshot with date as the name inside `destination_within_partition`\n* creates backups (copies of snapshots inside `destination_within_partition`) inside `destination_other_partition` for the case when source filesystem crashes\n* store snapshot name, date and how long snapshot should be kept in `destination_within_partition/history.db` (and `destination_other_partition/history.db`, since backups might have own retention settings)\n* reads old snapshots stored in `destination_within_partition/history.db` (and `destination_other_partition/history.db`) and remove them from `history.db` and from filesystem\n\n### Configuration\nConfiguration options are especially made self-explanatory:\n```json\n[\n\t{\n\t\t\"source_mounted_volume\"        : \"/\",\n\t\t\"destination_within_partition\" : \"/backup/root\",\n\t\t\"destination_other_partition\"  : null,\n\t\t\"date_format\"                  : \"Y-m-d_H:i:s\",\n\t\t\"keep_snapshots\"               : {\n\t\t\t\"hour\"  : 60,\n\t\t\t\"day\"   : 24,\n\t\t\t\"month\" : 30,\n\t\t\t\"year\"  : 48\n\t\t}\n\t},\n\t{\n\t\t\"source_mounted_volume\"        : \"/home\",\n\t\t\"destination_within_partition\" : \"/backup/home\",\n\t\t\"destination_other_partition\"  : \"/backup_external/home\",\n\t\t\"date_format\"                  : \"Y-m-d_H:i:s\",\n\t\t\"optimize_mounts\"              : false,\n\t\t\"keep_snapshots\"               : {\n\t\t\t\"hour\"  : 120,\n\t\t\t\"day\"   : 48,\n\t\t\t\"month\" : 60,\n\t\t\t\"year\"  : 96\n\t\t},\n\t\t\"keep_other_snapshots\"         : {\n\t\t\t\"hour\"  : -1,\n\t\t\t\"day\"   : 96,\n\t\t\t\"month\" : 120,\n\t\t\t\"year\"  : 192\n\t\t},\n\t\t\"minimum_delete_count\"         : 10,\n\t\t\"minimum_delete_count_other\"   : 10\n\t}\n]\n```\n\n* `source_mounted_volume` - string, absolute path, subvolume to backup/create snapshot of\n* `destination_within_partition` - string, absolute path, where to store snapshots, should be the same partition as `source_mounted_volume`\n* `destination_other_partition` - string, absolute path (or `null` if not needed), where to store actual backup, expected to be another BTRFS partition\n* `date_format` - string, date format as for PHP [date() function](https://secure.php.net/manual/en/function.date.php)\n* `keep_snapshots` - array with keys `hour`, `day`, `month` and `year`, each key contains number of snapshots that must be kept within corresponding time interval (`-1` means unlimited)\n* `keep_other_snapshots` - the same as `keep_snapshots`, but for backups, `keep_snapshots` by default\n* `optimize_mounts` - allows to avoid constant remounting root during external backups since it might be slow; `true` by default, might be disabled if necessary\n* `minimum_delete_count` - minimum number of snapshots to remove, is used to decrease fragmentation and thus improve performance, `1` by default\n* `minimum_delete_count_other` - the same as `minimum_delete_count`, but for backups, `minimum_delete_count` by default\n\nSave this config as `/etc/just-backup-btrfs.json` and customize as you like.\n\n### License\nMIT, feel free to hack it and share!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnazar-pc%2Fjust-backup-btrfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnazar-pc%2Fjust-backup-btrfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnazar-pc%2Fjust-backup-btrfs/lists"}