Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd3321e879 | |||
| 55e18cc613 | |||
| 9d5534c11e | |||
| 93d0823c82 | |||
| 0285eb31a7 | |||
| 4c4cd36f9f | |||
| 9e8c6f7732 | |||
| f305f00d91 | |||
| 3e06a8e2fa | |||
| 241716cf6d | |||
| 1b7f7fd140 |
248
README.md
248
README.md
@ -20,9 +20,21 @@
|
|||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
ZFS autobackup is used to periodicly backup ZFS filesystems to other locations. This is done using the very effcient zfs send and receive commands.
|
This is a tool I wrote to make replicating ZFS datasets easy and reliable. You can either use it as a backup tool or as a replication tool.
|
||||||
|
|
||||||
It has the following features:
|
You can select what to backup by setting a custom `ZFS property`. This allows you to set and forget: Configure it so it backups your entire pool, and you never have to worry about backupping again. Even new datasets you create later will be backupped.
|
||||||
|
|
||||||
|
Other settings are just specified on the commandline. This also makes it easier to setup and test zfs-autobackup and helps you fix all the issues you might encounter. When you're done you can just copy/paste your command to a cron or script.
|
||||||
|
|
||||||
|
Since its using ZFS commands, you can see what its actually doing by specifying `--debug`. This also helps a lot if you run into some strange problem or error. You can just copy-paste the command that fails and play around with it on the commandline. (also something I missed in other tools)
|
||||||
|
|
||||||
|
An imporant feature thats missing from other tools is a reliable `--test` option: This allows you to see what zfs-autobackup will do and tune your parameters. It will do everything, except make changes to your zfs datasets.
|
||||||
|
|
||||||
|
Another nice thing is progress reporting with `--progress`. Its very usefull with HUGE datasets, when you want to know how many hours/days it will take.
|
||||||
|
|
||||||
|
zfs-autobackup tries to be the easiest to use backup tool for zfs.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
* Works across operating systems: Tested with Linux, FreeBSD/FreeNAS and SmartOS.
|
* Works across operating systems: Tested with Linux, FreeBSD/FreeNAS and SmartOS.
|
||||||
* Works in combination with existing replication systems. (Like Proxmox HA)
|
* Works in combination with existing replication systems. (Like Proxmox HA)
|
||||||
@ -49,115 +61,31 @@ It has the following features:
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Use pip to install:
|
### Using pip
|
||||||
|
|
||||||
|
The recommended way on most servers is to use pip:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
[root@server ~]# pip install zfs-autobackup
|
[root@server ~]# pip install zfs-autobackup
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using easy_install
|
||||||
|
|
||||||
On older servers you might have to use easy_install
|
On older servers you might have to use easy_install
|
||||||
|
|
||||||
```console
|
```console
|
||||||
[root@server ~]# easy_install zfs-autobackup
|
[root@server ~]# easy_install zfs-autobackup
|
||||||
```
|
```
|
||||||
|
|
||||||
Its also possible to just download <https://raw.githubusercontent.com/psy0rz/zfs_autobackup/v3/bin/zfs_autobackup> and run it directly.
|
### Direct download
|
||||||
|
|
||||||
## Usage
|
Its also possible to just download <https://raw.githubusercontent.com/psy0rz/zfs_autobackup/master/bin/zfs-autobackup> and run it directly.
|
||||||
|
|
||||||
```console
|
The only requirement that is sometimes missing is the `argparse` python module. Optionally you can install `colorma` for colors.
|
||||||
[root@server ~]# zfs-autobackup --help
|
|
||||||
usage: zfs-autobackup [-h] [--ssh-source SSH_SOURCE] [--ssh-target SSH_TARGET]
|
|
||||||
[--keep-source KEEP_SOURCE] [--keep-target KEEP_TARGET]
|
|
||||||
[--no-snapshot] [--allow-empty] [--ignore-replicated]
|
|
||||||
[--no-holds] [--resume] [--strip-path STRIP_PATH]
|
|
||||||
[--buffer BUFFER] [--clear-refreservation]
|
|
||||||
[--clear-mountpoint]
|
|
||||||
[--filter-properties FILTER_PROPERTIES]
|
|
||||||
[--set-properties SET_PROPERTIES] [--rollback]
|
|
||||||
[--ignore-transfer-errors] [--raw] [--test] [--verbose]
|
|
||||||
[--debug] [--debug-output] [--progress]
|
|
||||||
backup_name target_path
|
|
||||||
|
|
||||||
ZFS autobackup 3.0-beta6
|
It should work with python 2.7 and higher.
|
||||||
|
|
||||||
positional arguments:
|
## Example
|
||||||
backup_name Name of the backup (you should set the zfs property
|
|
||||||
"autobackup:backup-name" to true on filesystems you
|
|
||||||
want to backup
|
|
||||||
target_path Target ZFS filesystem
|
|
||||||
|
|
||||||
optional arguments:
|
|
||||||
-h, --help show this help message and exit
|
|
||||||
--ssh-source SSH_SOURCE
|
|
||||||
Source host to get backup from. (user@hostname)
|
|
||||||
Default None.
|
|
||||||
--ssh-target SSH_TARGET
|
|
||||||
Target host to push backup to. (user@hostname) Default
|
|
||||||
None.
|
|
||||||
--keep-source KEEP_SOURCE
|
|
||||||
Thinning schedule for old source snapshots. Default:
|
|
||||||
10,1d1w,1w1m,1m1y
|
|
||||||
--keep-target KEEP_TARGET
|
|
||||||
Thinning schedule for old target snapshots. Default:
|
|
||||||
10,1d1w,1w1m,1m1y
|
|
||||||
--no-snapshot dont create new snapshot (usefull for finishing
|
|
||||||
uncompleted backups, or cleanups)
|
|
||||||
--allow-empty if nothing has changed, still create empty snapshots.
|
|
||||||
--ignore-replicated Ignore datasets that seem to be replicated some other
|
|
||||||
way. (No changes since lastest snapshot. Usefull for
|
|
||||||
proxmox HA replication)
|
|
||||||
--no-holds Dont lock snapshots on the source. (Usefull to allow
|
|
||||||
proxmox HA replication to switches nodes)
|
|
||||||
--resume support resuming of interrupted transfers by using the
|
|
||||||
zfs extensible_dataset feature (both zpools should
|
|
||||||
have it enabled) Disadvantage is that you need to use
|
|
||||||
zfs recv -A if another snapshot is created on the
|
|
||||||
target during a receive. Otherwise it will keep
|
|
||||||
failing.
|
|
||||||
--strip-path STRIP_PATH
|
|
||||||
number of directory to strip from path (use 1 when
|
|
||||||
cloning zones between 2 SmartOS machines)
|
|
||||||
--buffer BUFFER Use mbuffer with specified size to speedup zfs
|
|
||||||
transfer. (e.g. --buffer 1G) Will also show nice
|
|
||||||
progress output.
|
|
||||||
--clear-refreservation
|
|
||||||
Filter "refreservation" property. (recommended, safes
|
|
||||||
space. same as --filter-properties refreservation)
|
|
||||||
--clear-mountpoint Filter "canmount" property. You still have to set
|
|
||||||
canmount=noauto on the backup server. (recommended,
|
|
||||||
prevents mount conflicts. same as --filter-properties
|
|
||||||
canmount)
|
|
||||||
--filter-properties FILTER_PROPERTIES
|
|
||||||
List of propererties to "filter" when receiving
|
|
||||||
filesystems. (you can still restore them with zfs
|
|
||||||
inherit -S)
|
|
||||||
--set-properties SET_PROPERTIES
|
|
||||||
List of propererties to override when receiving
|
|
||||||
filesystems. (you can still restore them with zfs
|
|
||||||
inherit -S)
|
|
||||||
--rollback Rollback changes on the target before starting a
|
|
||||||
backup. (normally you can prevent changes by setting
|
|
||||||
the readonly property on the target_path to on)
|
|
||||||
--ignore-transfer-errors
|
|
||||||
Ignore transfer errors (still checks if received
|
|
||||||
filesystem exists. usefull for acltype errors)
|
|
||||||
--raw For encrypted datasets, send data exactly as it exists
|
|
||||||
on disk.
|
|
||||||
--test dont change anything, just show what would be done
|
|
||||||
(still does all read-only operations)
|
|
||||||
--verbose verbose output
|
|
||||||
--debug Show zfs commands that are executed, stops after an
|
|
||||||
exception.
|
|
||||||
--debug-output Show zfs commands and their output/exit codes. (noisy)
|
|
||||||
--progress show zfs progress output (to stderr)
|
|
||||||
|
|
||||||
When a filesystem fails, zfs_backup will continue and report the number of
|
|
||||||
failures at that end. Also the exit code will indicate the number of failures.
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Backup example
|
|
||||||
|
|
||||||
In this example we're going to backup a machine called `pve` to our backupserver.
|
In this example we're going to backup a machine called `pve` to our backupserver.
|
||||||
|
|
||||||
@ -197,14 +125,16 @@ rpool/swap autobackup:offsite1 false
|
|||||||
|
|
||||||
### Running zfs-autobackup
|
### Running zfs-autobackup
|
||||||
|
|
||||||
|
Before you start, make sure you can login to the server without password, by using `SSH keys`. Look at the troubleshooting section for more info.
|
||||||
|
|
||||||
There are 2 ways to run the backup, but the endresult is always the same. Its just a matter of security (trust relations between the servers) and preference.
|
There are 2 ways to run the backup, but the endresult is always the same. Its just a matter of security (trust relations between the servers) and preference.
|
||||||
|
|
||||||
First install the ssh-key on the server that you specify with --ssh-source or --ssh-target.
|
#### Method 1: Pull backup
|
||||||
|
|
||||||
#### Method 1: Run the script on the backup server and pull the data from the server specfied by --ssh-source. This is usually the preferred way and prevents a hacked server from accesing the backup-data
|
Run the script on the backup server and pull the data from the server specfied by --ssh-source. This is usually the preferred way and prevents a hacked server from accesing the backup-data.
|
||||||
|
|
||||||
```console
|
```console
|
||||||
[root@backup ~]# zfs-autobackup --ssh-source pve.server.com offsite1 backup/pve --progress --verbose --resume
|
[root@backup ~]# zfs-autobackup --ssh-source pve.server.com offsite1 backup/pve --progress --verbose
|
||||||
|
|
||||||
#### Settings summary
|
#### Settings summary
|
||||||
[Source] Datasets on: pve.server.com
|
[Source] Datasets on: pve.server.com
|
||||||
@ -236,7 +166,6 @@ First install the ssh-key on the server that you specify with --ssh-source or --
|
|||||||
[Source] Creating snapshot offsite1-20200218180123
|
[Source] Creating snapshot offsite1-20200218180123
|
||||||
|
|
||||||
#### Transferring
|
#### Transferring
|
||||||
[Target] backup/pve/rpool/ROOT/pve-1@offsite1-20200218175435: resuming
|
|
||||||
[Target] backup/pve/rpool/ROOT/pve-1@offsite1-20200218175435: receiving full
|
[Target] backup/pve/rpool/ROOT/pve-1@offsite1-20200218175435: receiving full
|
||||||
[Target] backup/pve/rpool/ROOT/pve-1@offsite1-20200218175547: receiving incremental
|
[Target] backup/pve/rpool/ROOT/pve-1@offsite1-20200218175547: receiving incremental
|
||||||
[Target] backup/pve/rpool/ROOT/pve-1@offsite1-20200218175706: receiving incremental
|
[Target] backup/pve/rpool/ROOT/pve-1@offsite1-20200218175706: receiving incremental
|
||||||
@ -247,10 +176,12 @@ First install the ssh-key on the server that you specify with --ssh-source or --
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Method 2: Run the script on the server and push the data to the backup server specified by --ssh-target
|
#### Method 2: push backup
|
||||||
|
|
||||||
|
Run the script on the server and push the data to the backup server specified by --ssh-target.
|
||||||
|
|
||||||
```console
|
```console
|
||||||
[root@pve ~]# zfs-autobackup --ssh-target backup.server.com offsite1 backup/pve --progress --verbose --resume
|
[root@pve ~]# zfs-autobackup --ssh-target backup.server.com offsite1 backup/pve --progress --verbose
|
||||||
|
|
||||||
#### Settings summary
|
#### Settings summary
|
||||||
[Source] Datasets are local
|
[Source] Datasets are local
|
||||||
@ -270,24 +201,119 @@ First install the ssh-key on the server that you specify with --ssh-source or --
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Automatic backups
|
### Automatic backups
|
||||||
|
|
||||||
Now everytime you run the command, zfs-autobackup will create a new snapshot and replicate your data.
|
Now everytime you run the command, zfs-autobackup will create a new snapshot and replicate your data.
|
||||||
|
|
||||||
Older snapshots will evertually be deleted, depending on the --keep-source and --keep-target settings. (The defaults are shown above under the 'Settings summary')
|
Older snapshots will evertually be deleted, depending on the `--keep-source` and `--keep-target` settings. (The defaults are shown above under the 'Settings summary')
|
||||||
|
|
||||||
Once you've got the correct settings for your situation, you can just store the command in a cronjob. Or just create a script and run it manually when you need it.
|
Once you've got the correct settings for your situation, you can just store the command in a cronjob.
|
||||||
|
|
||||||
|
Or just create a script and run it manually when you need it.
|
||||||
|
|
||||||
## Tips
|
## Tips
|
||||||
|
|
||||||
* Use ```--verbose``` to see details, otherwise zfs-autobackup will be quiet and only show errors, like a nice unix command.
|
* Use ```--verbose``` to see details, otherwise zfs-autobackup will be quiet and only show errors, like a nice unix command.
|
||||||
* Use ```--debug``` if something goes wrong and you want to see the commands that are executed. This will also stop at the first error.
|
* Use ```--debug``` if something goes wrong and you want to see the commands that are executed. This will also stop at the first error.
|
||||||
* Use ```--resume``` to be able to resume aborted backups. (not all zfs versions support this)
|
* Use ```--resume``` to be able to resume aborted backups. (not all zfs versions support this)
|
||||||
* Set the ```readonly``` property of the target filesystem to ```on```. This prevents changes on the target side. If there are changes the next backup will fail and will require a zfs rollback. (by using the --rollback option for example)
|
* Set the ```readonly``` property of the target filesystem to ```on```. This prevents changes on the target side. (Normally, if there are changes the next backup will fail and will require a zfs rollback.) Note that readonly means you cant change the CONTENTS of the dataset directly. Its still possible to receive new datasets and manipulate properties etc.
|
||||||
* Use ```--clear-refreservation``` to save space on your backup server.
|
* Use ```--clear-refreservation``` to save space on your backup server.
|
||||||
* Use ```--clear-mountpoint``` to prevent the target server from mounting the backupped filesystem in the wrong place during a reboot.
|
* Use ```--clear-mountpoint``` to prevent the target server from mounting the backupped filesystem in the wrong place during a reboot.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Here you find all the options:
|
||||||
|
|
||||||
|
```console
|
||||||
|
[root@server ~]# zfs-autobackup --help
|
||||||
|
usage: zfs-autobackup [-h] [--ssh-source SSH_SOURCE] [--ssh-target SSH_TARGET]
|
||||||
|
[--keep-source KEEP_SOURCE] [--keep-target KEEP_TARGET]
|
||||||
|
[--no-snapshot] [--allow-empty] [--ignore-replicated]
|
||||||
|
[--no-holds] [--resume] [--strip-path STRIP_PATH]
|
||||||
|
[--buffer BUFFER] [--clear-refreservation]
|
||||||
|
[--clear-mountpoint]
|
||||||
|
[--filter-properties FILTER_PROPERTIES]
|
||||||
|
[--set-properties SET_PROPERTIES] [--rollback]
|
||||||
|
[--ignore-transfer-errors] [--raw] [--test] [--verbose]
|
||||||
|
[--debug] [--debug-output] [--progress]
|
||||||
|
backup_name target_path
|
||||||
|
|
||||||
|
ZFS autobackup 3.0-rc3
|
||||||
|
|
||||||
|
positional arguments:
|
||||||
|
backup_name Name of the backup (you should set the zfs property
|
||||||
|
"autobackup:backup-name" to true on filesystems you
|
||||||
|
want to backup
|
||||||
|
target_path Target ZFS filesystem
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--ssh-source SSH_SOURCE
|
||||||
|
Source host to get backup from. (user@hostname)
|
||||||
|
Default None.
|
||||||
|
--ssh-target SSH_TARGET
|
||||||
|
Target host to push backup to. (user@hostname) Default
|
||||||
|
None.
|
||||||
|
--keep-source KEEP_SOURCE
|
||||||
|
Thinning schedule for old source snapshots. Default:
|
||||||
|
10,1d1w,1w1m,1m1y
|
||||||
|
--keep-target KEEP_TARGET
|
||||||
|
Thinning schedule for old target snapshots. Default:
|
||||||
|
10,1d1w,1w1m,1m1y
|
||||||
|
--no-snapshot dont create new snapshot (usefull for finishing
|
||||||
|
uncompleted backups, or cleanups)
|
||||||
|
--allow-empty if nothing has changed, still create empty snapshots.
|
||||||
|
--ignore-replicated Ignore datasets that seem to be replicated some other
|
||||||
|
way. (No changes since lastest snapshot. Usefull for
|
||||||
|
proxmox HA replication)
|
||||||
|
--no-holds Dont lock snapshots on the source. (Usefull to allow
|
||||||
|
proxmox HA replication to switches nodes)
|
||||||
|
--resume support resuming of interrupted transfers by using the
|
||||||
|
zfs extensible_dataset feature (both zpools should
|
||||||
|
have it enabled) Disadvantage is that you need to use
|
||||||
|
zfs recv -A if another snapshot is created on the
|
||||||
|
target during a receive. Otherwise it will keep
|
||||||
|
failing.
|
||||||
|
--strip-path STRIP_PATH
|
||||||
|
number of directory to strip from path (use 1 when
|
||||||
|
cloning zones between 2 SmartOS machines)
|
||||||
|
--clear-refreservation
|
||||||
|
Filter "refreservation" property. (recommended, safes
|
||||||
|
space. same as --filter-properties refreservation)
|
||||||
|
--clear-mountpoint Filter "canmount" property. You still have to set
|
||||||
|
canmount=noauto on the backup server. (recommended,
|
||||||
|
prevents mount conflicts. same as --filter-properties
|
||||||
|
canmount)
|
||||||
|
--filter-properties FILTER_PROPERTIES
|
||||||
|
List of propererties to "filter" when receiving
|
||||||
|
filesystems. (you can still restore them with zfs
|
||||||
|
inherit -S)
|
||||||
|
--set-properties SET_PROPERTIES
|
||||||
|
List of propererties to override when receiving
|
||||||
|
filesystems. (you can still restore them with zfs
|
||||||
|
inherit -S)
|
||||||
|
--rollback Rollback changes on the target before starting a
|
||||||
|
backup. (normally you can prevent changes by setting
|
||||||
|
the readonly property on the target_path to on)
|
||||||
|
--ignore-transfer-errors
|
||||||
|
Ignore transfer errors (still checks if received
|
||||||
|
filesystem exists. usefull for acltype errors)
|
||||||
|
--raw For encrypted datasets, send data exactly as it exists
|
||||||
|
on disk.
|
||||||
|
--test dont change anything, just show what would be done
|
||||||
|
(still does all read-only operations)
|
||||||
|
--verbose verbose output
|
||||||
|
--debug Show zfs commands that are executed, stops after an
|
||||||
|
exception.
|
||||||
|
--debug-output Show zfs commands and their output/exit codes. (noisy)
|
||||||
|
--progress show zfs progress output (to stderr)
|
||||||
|
|
||||||
|
When a filesystem fails, zfs_backup will continue and report the number of
|
||||||
|
failures at that end. Also the exit code will indicate the number of failures.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Speeding up SSH and prevent connection flooding
|
### Speeding up SSH and prevent connection flooding
|
||||||
|
|
||||||
Add this to your ~/.ssh/config:
|
Add this to your ~/.ssh/config:
|
||||||
@ -323,6 +349,14 @@ Look in man ssh_config for many more options.
|
|||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
|
### It keeps asking for my SSH password
|
||||||
|
|
||||||
|
You forgot to setup automatic login via SSH keys:
|
||||||
|
|
||||||
|
* Create a SSH key on the server that you want to run zfs-autobackup on. Use `ssh-keygen`.
|
||||||
|
* Copy the public key to your clipboard. Get it with `cat /root/.ssh/id_rsa.pub`
|
||||||
|
* Add the key to the server you specified with --ssh-source or --ssh-target. Create and add it to `/root/.ssh/authorized_keys`
|
||||||
|
|
||||||
> ### cannot receive incremental stream: invalid backup stream
|
> ### cannot receive incremental stream: invalid backup stream
|
||||||
|
|
||||||
This usually means you've created a new snapshot on the target side during a backup:
|
This usually means you've created a new snapshot on the target side during a backup:
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
zfs_autobackup
|
|
||||||
1493
bin/zfs-autobackup
Executable file
1493
bin/zfs-autobackup
Executable file
File diff suppressed because it is too large
Load Diff
1472
bin/zfs_autobackup
1472
bin/zfs_autobackup
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
|||||||
zfs_autobackup
|
zfs-autobackup
|
||||||
2
setup.py
2
setup.py
@ -17,7 +17,7 @@ setuptools.setup(
|
|||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
|
||||||
url="https://github.com/psy0rz/zfs_autobackup",
|
url="https://github.com/psy0rz/zfs_autobackup",
|
||||||
scripts=["bin/zfs_autobackup", "bin/zfs-autobackup"],
|
scripts=["bin/zfs-autobackup"],
|
||||||
packages=setuptools.find_packages(),
|
packages=setuptools.find_packages(),
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Programming Language :: Python :: 2",
|
"Programming Language :: Python :: 2",
|
||||||
|
|||||||
Reference in New Issue
Block a user