Compare commits
9 commits
Author | SHA1 | Date | |
---|---|---|---|
04755ebc5c | |||
|
5fb174bcc6 | ||
9cc1e599cf | |||
305b08b544 | |||
cb7d9a4525 | |||
ba2475aed2 | |||
1fbc754a9d | |||
075263fecc | |||
|
dec3557b45 |
2 changed files with 29 additions and 8 deletions
|
@ -8,7 +8,7 @@ Edit example config file, run script and config as parameter.
|
||||||
|
|
||||||
__Requirements:__
|
__Requirements:__
|
||||||
|
|
||||||
zfSnap, pv, Ubuntu (tested on Ubuntu 18.04)
|
zfsnap, pv, lzop, Manjaro (tested on 6.6.2019)
|
||||||
|
|
||||||
__THE PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.__
|
__THE PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.__
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,20 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ ! -f "$1" ]]
|
||||||
|
then
|
||||||
|
echo "Config file not exists!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$2" ]
|
||||||
|
then
|
||||||
|
lock_variable="/var/lock/zfs-backup-mm"
|
||||||
|
else
|
||||||
|
lock_variable="$2"
|
||||||
|
fi
|
||||||
|
|
||||||
(
|
(
|
||||||
flock -n 200 || { echo 'locked via flock on file /var/lock/zfs-backup-mm' ; exit 1; }
|
flock -n 200 || { echo "locked via flock on file $lock_variable" ; exit 1; }
|
||||||
|
|
||||||
zfsnap_block () {
|
zfsnap_block () {
|
||||||
|
|
||||||
|
@ -9,8 +23,13 @@ IFS='
|
||||||
if [ $zfsnap_enable = "y" ]; then
|
if [ $zfsnap_enable = "y" ]; then
|
||||||
for dataset in $source_datasets;
|
for dataset in $source_datasets;
|
||||||
do
|
do
|
||||||
echo "Tuning zfSnap for "$dataset""
|
echo "Tuning zfsnap for "$dataset""
|
||||||
for command in $(zfSnap -n -d -zpool28fix -a "$zfsnap_days_keep_snaps"d "$dataset" | grep "$dataset")
|
for command in $(zfsnap snapshot -n -a "$zfsnap_days_keep_snaps"d "$dataset" | grep "$dataset")
|
||||||
|
do
|
||||||
|
echo "Doing "$command""
|
||||||
|
eval "$command";
|
||||||
|
done
|
||||||
|
for command in $(zfsnap destroy -n -F "$zfsnap_days_keep_snaps"d "$dataset" | grep "$dataset")
|
||||||
do
|
do
|
||||||
echo "Doing "$command""
|
echo "Doing "$command""
|
||||||
eval "$command";
|
eval "$command";
|
||||||
|
@ -38,14 +57,15 @@ backup_snap=$(echo "$backups_server_zfs_snapshots" | grep "$backup_server_datase
|
||||||
backup_snaps=$(echo "$backups_server_zfs_snapshots" | grep "$backup_server_dataset"/"$dataset_clean"@ | grep -E "....-..-.._........--"$zfsnap_days_keep_snaps"d" | cut -d"@" -f2 | cut -d" " -f1)
|
backup_snaps=$(echo "$backups_server_zfs_snapshots" | grep "$backup_server_dataset"/"$dataset_clean"@ | grep -E "....-..-.._........--"$zfsnap_days_keep_snaps"d" | cut -d"@" -f2 | cut -d" " -f1)
|
||||||
source_backups_server_match=$(grep -Fxf <(echo "$source_snaps") <(echo "$backup_snaps"))
|
source_backups_server_match=$(grep -Fxf <(echo "$source_snaps") <(echo "$backup_snaps"))
|
||||||
source_backups_server_match_tailed=$(echo "$source_backups_server_match" | tail -n1)
|
source_backups_server_match_tailed=$(echo "$source_backups_server_match" | tail -n1)
|
||||||
|
dataset_recordsize=$(zfs get recordsize -H -o value "$dataset")
|
||||||
|
|
||||||
if [ -z "$backup_snap" ]
|
if [ -z "$backup_snap" ]
|
||||||
then
|
then
|
||||||
echo "Snapshot on backup server not found, sending "$dataset"@"$source_snap" to server "$backup_server" "$backup_server_dataset"/"$dataset_clean""
|
echo "Snapshot on backup server not found, sending "$dataset"@"$source_snap" to server "$backup_server" "$backup_server_dataset"/"$dataset_clean""
|
||||||
zfs send -c "$dataset"@"$source_snap" | pv -L "$shape_megabytes"m | ssh -$backup_server_ipv "$backup_server" -p "$backup_server_port" zfs recv "$backup_server_dataset"/"$dataset_clean" && echo "Send OK"
|
zfs send "$dataset"@"$source_snap" | lzop | pv -L "$shape_megabytes"m | ssh -$backup_server_ipv "$backup_server" -p "$backup_server_port" "lzop -d | zfs recv -o recordsize="$dataset_recordsize" "$backup_server_dataset"/"$dataset_clean"" && echo "Send OK"
|
||||||
else
|
else
|
||||||
echo "Snapshot on backup server found, sending incremental from "$dataset"@"$source_backups_server_match_tailed" to "$dataset"@"$source_snap" to server "$backup_server" "$backup_server_dataset"/"$dataset_clean""
|
echo "Snapshot on backup server found, sending incremental from "$dataset"@"$source_backups_server_match_tailed" to "$dataset"@"$source_snap" to server "$backup_server" "$backup_server_dataset"/"$dataset_clean""
|
||||||
zfs send -ci "$dataset"@"$source_backups_server_match_tailed" "$dataset"@"$source_snap" | pv -L "$shape_megabytes"m | ssh -$backup_server_ipv "$backup_server" -p "$backup_server_port" zfs recv "$backup_server_dataset"/"$dataset_clean" -F && echo "Send OK"
|
zfs send -I "$dataset"@"$source_backups_server_match_tailed" "$dataset"@"$source_snap" | lzop | pv -L "$shape_megabytes"m | ssh -$backup_server_ipv "$backup_server" -p "$backup_server_port" "lzop -d | zfs recv -o recordsize="$dataset_recordsize" "$backup_server_dataset"/"$dataset_clean" -F" && echo "Send OK"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
del_snaps_block
|
del_snaps_block
|
||||||
|
@ -57,7 +77,7 @@ for dataset in $source_datasets;
|
||||||
do
|
do
|
||||||
|
|
||||||
dataset_clean=$(echo $dataset | grep -o '[^/]*$')
|
dataset_clean=$(echo $dataset | grep -o '[^/]*$')
|
||||||
snaps_to_delete=$(echo "$backups_server_zfs_snapshots" | grep "$backup_server_dataset"/"$dataset_clean"@ | grep -E "....-..-.._........--"$zfsnap_days_keep_snaps"d" | head -n -"$backup_server_number_keep_snaps" | cut -d" " -f1)
|
snaps_to_delete=$(echo "$backups_server_zfs_snapshots" | grep "$backup_server_dataset"/"$dataset_clean"@ | head -n -"$backup_server_number_keep_snaps" | cut -d" " -f1)
|
||||||
|
|
||||||
for snap in $snaps_to_delete
|
for snap in $snaps_to_delete
|
||||||
do
|
do
|
||||||
|
@ -78,4 +98,5 @@ if [[ $# -eq 0 ]] ; then
|
||||||
fi
|
fi
|
||||||
source $1
|
source $1
|
||||||
zfsnap_block
|
zfsnap_block
|
||||||
) 200>/var/lock/zfs-backup-mm
|
) 200>$lock_variable
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue