update
22
Home.md
22
Home.md
@ -237,29 +237,9 @@ This also allows you to make several snapshots during the day, but only backup t
|
||||
* [Thinning out obsolete snapshots](Thinner.md)
|
||||
* [Handling ZFS encryption](Encryption.md)
|
||||
* [Transfer bufferings, compression and rate limiting.](Pipes.md)
|
||||
* [Custom Pre- and post-snapshot commands](Pre+and+post+snapshot+commands.md)
|
||||
|
||||
|
||||
## Running custom commands before and after snapshotting
|
||||
|
||||
You can run commands before and after the snapshot to freeze databases to make the on for example to make the on-disk data consistent before snapshotting.
|
||||
|
||||
The commands will be executed on the source side. Use the `--pre-snapshot-cmd` and `--post-snapshot-cmd` options for this.
|
||||
|
||||
For example:
|
||||
|
||||
```sh
|
||||
zfs-autobackup \
|
||||
--pre-snapshot-cmd 'daemon -f jexec mysqljail1 mysql -s -e "set autocommit=0;flush logs;flush tables with read lock;\\! echo \$\$ > /tmp/mysql_lock.pid && sleep 60"' \
|
||||
--pre-snapshot-cmd 'daemon -f jexec mysqljail2 mysql -s -e "set autocommit=0;flush logs;flush tables with read lock;\\! echo \$\$ > /tmp/mysql_lock.pid && sleep 60"' \
|
||||
--post-snapshot-cmd 'pkill -F /jails/mysqljail1/tmp/mysql_lock.pid' \
|
||||
--post-snapshot-cmd 'pkill -F /jails/mysqljail2/tmp/mysql_lock.pid' \
|
||||
backupfs1
|
||||
```
|
||||
|
||||
Failure handling during pre/post commands:
|
||||
|
||||
* If a pre-command fails, zfs-autobackup will exit with an error. (after executing the post-commands)
|
||||
* All post-commands are always executed. Even if the pre-commands or actual snapshot have failed. This way you can be sure that stuff is always cleanedup and unfreezed.
|
||||
|
||||
## Tips
|
||||
|
||||
|
||||
45
Pre and post snapshot commands.md
Normal file
45
Pre and post snapshot commands.md
Normal file
@ -0,0 +1,45 @@
|
||||
# Running custom commands before and after snapshotting
|
||||
|
||||
You can run commands before and after the snapshot to freeze databases for example, to make the on-disk data consistent before snapshotting.
|
||||
|
||||
## Method 1: Use snapshot mode
|
||||
|
||||
Its possible to use zfs-autobackup in snapshot-only mode. This way you can just create a script that contains the pre and post steps:
|
||||
```console
|
||||
|
||||
#freeze stuff
|
||||
some-freeze-command
|
||||
|
||||
#make snapshot
|
||||
zfs-autobackup backup1
|
||||
|
||||
#unfreeze stuff
|
||||
some-unfreeze-command
|
||||
|
||||
#make backup
|
||||
zfs-autobackup backup1 --no-snapshot --ssh-target backupserver backups/db1
|
||||
|
||||
|
||||
```
|
||||
|
||||
This has the disadvantage that you might have to do the error handling yourself. Also if the source is remote, you have to use the correct ssh command and escaping as well.
|
||||
|
||||
## Method 2: Use --pre-snapshot-cmd and --post-snapshot-cmd
|
||||
|
||||
The commands will be executed on the source side. Use the `--pre-snapshot-cmd` and `--post-snapshot-cmd` options for this.
|
||||
|
||||
For example:
|
||||
|
||||
```sh
|
||||
zfs-autobackup \
|
||||
--pre-snapshot-cmd 'some-freeze-command'\
|
||||
--post-snapshot-cmd 'some-unfreeze-command'\
|
||||
--ssh-target backupserver backups/db1
|
||||
```
|
||||
|
||||
Some rules:
|
||||
* The pre and post commands are always executed on the source side. (via ssh if needed)
|
||||
* If a pre-command fails, zfs-autobackup will exit with an error. (after executing the post-commands)
|
||||
* All post-commands are always executed. Even if the pre-commands or actual snapshot have failed. This way you can be sure that stuff is always cleanedup and unfreezed.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user