Compare commits
5 commits
116697af9f
...
706c4028f8
Author | SHA1 | Date | |
---|---|---|---|
![]() |
706c4028f8 | ||
![]() |
3cd41adeaf | ||
![]() |
8a13421577 | ||
![]() |
9ff8dce802 | ||
![]() |
49081248ae |
7 changed files with 65 additions and 19 deletions
|
@ -33,7 +33,7 @@ zfs snap "$source_dataset@$new_bookmark"
|
||||||
if zfs list -t bookmark -H -o name | grep "^$source_dataset#$bookmark_prefix" | wc -l | grep -q "^0$"
|
if zfs list -t bookmark -H -o name | grep "^$source_dataset#$bookmark_prefix" | wc -l | grep -q "^0$"
|
||||||
then
|
then
|
||||||
echo "INITIAL BACKUP"
|
echo "INITIAL BACKUP"
|
||||||
# do in subshell, otherwise ctr+c will lead to 0 exitcode
|
# do in subshell, otherwise ctr+c will lead to 0 exitcode
|
||||||
$(zfs send -v "$source_dataset@$new_bookmark" | $ssh sudo zfs recv -F "$target_dataset")
|
$(zfs send -v "$source_dataset@$new_bookmark" | $ssh sudo zfs recv -F "$target_dataset")
|
||||||
else
|
else
|
||||||
echo "INCREMENTAL BACKUP"
|
echo "INCREMENTAL BACKUP"
|
||||||
|
@ -44,6 +44,19 @@ fi
|
||||||
|
|
||||||
if [[ "$?" == "0" ]]
|
if [[ "$?" == "0" ]]
|
||||||
then
|
then
|
||||||
|
|
||||||
|
# delete old local bookmarks
|
||||||
|
for destroyable_bookmark in $(zfs list -t bookmark -H -o name "$dataset" | grep "^$dataset#$bookmark_prefix")
|
||||||
|
do
|
||||||
|
zfs destroy "$destroyable_bookmark"
|
||||||
|
done
|
||||||
|
|
||||||
|
# delete snapshots from bookmarks (except newest, even of not necessary; maybe for resuming tho)
|
||||||
|
for destroyable_snapshot in $($ssh sudo zfs list -t snapshot -H -o name "$dataset" | grep "^$dataset@$bookmark_prefix" | grep -v "$new_bookmark")
|
||||||
|
do
|
||||||
|
$ssh sudo zfs destroy "$destroyable_snapshot"
|
||||||
|
done
|
||||||
|
|
||||||
zfs bookmark "$source_dataset@$new_bookmark" "$source_dataset#$new_bookmark"
|
zfs bookmark "$source_dataset@$new_bookmark" "$source_dataset#$new_bookmark"
|
||||||
zfs destroy "$source_dataset@$new_bookmark" # keep snapshots?
|
zfs destroy "$source_dataset@$new_bookmark" # keep snapshots?
|
||||||
echo "SUCCESS"
|
echo "SUCCESS"
|
||||||
|
|
|
@ -4,3 +4,6 @@ Host *
|
||||||
GSSAPIAuthentication yes
|
GSSAPIAuthentication yes
|
||||||
StrictHostKeyChecking yes
|
StrictHostKeyChecking yes
|
||||||
GlobalKnownHostsFile /etc/ssh/ssh_known_hosts
|
GlobalKnownHostsFile /etc/ssh/ssh_known_hosts
|
||||||
|
ControlMaster auto
|
||||||
|
ControlPath ~/.ssh/multiplex-%C
|
||||||
|
ControlPersist 5m
|
||||||
|
|
|
@ -22,7 +22,7 @@ def systemd(metadata):
|
||||||
'Persistent': config.get('persistent', False),
|
'Persistent': config.get('persistent', False),
|
||||||
'Unit': f'{name}.service',
|
'Unit': f'{name}.service',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
f'{name}.service': {
|
f'{name}.service': {
|
||||||
'Unit':{
|
'Unit':{
|
||||||
'Description': f'{name} timer service',
|
'Description': f'{name} timer service',
|
||||||
|
@ -37,9 +37,11 @@ def systemd(metadata):
|
||||||
})
|
})
|
||||||
if config.get('working_dir'):
|
if config.get('working_dir'):
|
||||||
units[f'{name}.service']['Service']['WorkingDirectory'] = config['working_dir']
|
units[f'{name}.service']['Service']['WorkingDirectory'] = config['working_dir']
|
||||||
|
if config.get('success_exit_status'):
|
||||||
|
units[f'{name}.service']['Service']['SuccessExitStatus'] = config['success_exit_status']
|
||||||
|
|
||||||
services[f'{name}.timer'] = {}
|
services[f'{name}.timer'] = {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'systemd': {
|
'systemd': {
|
||||||
'units': units,
|
'units': units,
|
||||||
|
|
|
@ -17,7 +17,7 @@ MIN_UPTIME=$(expr 60 \* 15)
|
||||||
if [[ "$UPTIME" -lt "$MIN_UPTIME" ]]
|
if [[ "$UPTIME" -lt "$MIN_UPTIME" ]]
|
||||||
then
|
then
|
||||||
echo "ABORT: uptime of ${UPTIME}s is lower than minimum of ${MIN_UPTIME}s"
|
echo "ABORT: uptime of ${UPTIME}s is lower than minimum of ${MIN_UPTIME}s"
|
||||||
exit 0
|
exit 75
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# CHECK FOR RUNNING TIMERS
|
# CHECK FOR RUNNING TIMERS
|
||||||
|
@ -30,7 +30,7 @@ do
|
||||||
elif systemctl is-active "$SERVICE" --quiet
|
elif systemctl is-active "$SERVICE" --quiet
|
||||||
then
|
then
|
||||||
echo "ABORT: service $SERVICE is running by timer"
|
echo "ABORT: service $SERVICE is running by timer"
|
||||||
exit 0
|
exit 75
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ LOGINS=$(netstat -tnpa | grep 'ESTABLISHED.*sshd' | tr -s ' ' | cut -d' ' -f5,7-
|
||||||
if ! [[ -z "$LOGINS" ]]
|
if ! [[ -z "$LOGINS" ]]
|
||||||
then
|
then
|
||||||
echo "ABORT: users logged in: $LOGINS"
|
echo "ABORT: users logged in: $LOGINS"
|
||||||
exit 0
|
exit 75
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# SUSPEND!
|
# SUSPEND!
|
||||||
|
@ -48,8 +48,26 @@ fi
|
||||||
if [[ "$1" = check ]]
|
if [[ "$1" = check ]]
|
||||||
then
|
then
|
||||||
echo "WOULD SESPEND"
|
echo "WOULD SESPEND"
|
||||||
|
exit 0
|
||||||
else
|
else
|
||||||
|
echo "SESPENDING AFTER TIMEOUT"
|
||||||
|
|
||||||
|
for i in 1 2 3 4 5 6
|
||||||
|
do
|
||||||
|
echo "TIMEOUT ${i} success"
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
# check if condition is still met
|
||||||
|
if "$0" check
|
||||||
|
then
|
||||||
|
continue
|
||||||
|
else
|
||||||
|
echo "SESPENSION ABORTED"
|
||||||
|
exit 75
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo "SESPENDING"
|
echo "SESPENDING"
|
||||||
sleep 60
|
|
||||||
systemctl suspend
|
systemctl suspend
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -6,6 +6,7 @@ defaults = {
|
||||||
'packages': {
|
'packages': {
|
||||||
'jq': {},
|
'jq': {},
|
||||||
'ethtool': {},
|
'ethtool': {},
|
||||||
|
'net-tools': {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -20,6 +21,7 @@ def timer(metadata):
|
||||||
'suspend-if-idle': {
|
'suspend-if-idle': {
|
||||||
'command': f'suspend_if_idle',
|
'command': f'suspend_if_idle',
|
||||||
'when': 'minutely',
|
'when': 'minutely',
|
||||||
|
'success_exit_status': '75',
|
||||||
'env': {
|
'env': {
|
||||||
'THIS_SERVICE': 'suspend-if-idle.service',
|
'THIS_SERVICE': 'suspend-if-idle.service',
|
||||||
},
|
},
|
||||||
|
@ -35,7 +37,7 @@ def wake_command(metadata):
|
||||||
waker_hostname = repo.get_node(metadata.get('wol-sleeper/waker')).hostname
|
waker_hostname = repo.get_node(metadata.get('wol-sleeper/waker')).hostname
|
||||||
mac = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/mac")
|
mac = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/mac")
|
||||||
ip = ip_interface(metadata.get(f"network/{metadata.get('wol-sleeper/network')}/ipv4")).ip
|
ip = ip_interface(metadata.get(f"network/{metadata.get('wol-sleeper/network')}/ipv4")).ip
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'wol-sleeper': {
|
'wol-sleeper': {
|
||||||
'wake_command': f"ssh -o StrictHostKeyChecking=no wol@{waker_hostname} 'wakeonlan {mac} && while ! ping {ip} -c1 -W3; do true; done'",
|
'wake_command': f"ssh -o StrictHostKeyChecking=no wol@{waker_hostname} 'wakeonlan {mac} && while ! ping {ip} -c1 -W3; do true; done'",
|
||||||
|
@ -49,7 +51,7 @@ def wake_command(metadata):
|
||||||
)
|
)
|
||||||
def systemd(metadata):
|
def systemd(metadata):
|
||||||
interface = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/interface")
|
interface = metadata.get(f"network/{metadata.get('wol-sleeper/network')}/interface")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'systemd': {
|
'systemd': {
|
||||||
'units': {
|
'units': {
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
set -exu
|
set -exu
|
||||||
|
|
||||||
ssh="ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@${server_ip}"
|
ssh="ssh -o ConnectTimeout=5 root@${server_ip}"
|
||||||
bookmark_prefix="auto-mirror_"
|
bookmark_prefix="auto-mirror_"
|
||||||
new_bookmark="$bookmark_prefix$(date +"%Y-%m-%d_%H:%M:%S")"
|
new_bookmark="$bookmark_prefix$(date +"%Y-%m-%d_%H:%M:%S")"
|
||||||
|
|
||||||
for dataset in $(zfs list -t filesystem -H -o name)
|
for dataset in $(zfs list -t filesystem -H -o name)
|
||||||
do
|
do
|
||||||
echo "MIRRORING $dataset"
|
echo "MIRRORING $dataset"
|
||||||
|
|
||||||
if ! $ssh sudo zfs list -t filesystem -H -o name | grep -q "^$dataset$"
|
if ! $ssh sudo zfs list -t filesystem -H -o name | grep -q "^$dataset$"
|
||||||
then
|
then
|
||||||
echo "CREATING PARENT DATASET..."
|
echo "CREATING PARENT DATASET..."
|
||||||
|
@ -17,11 +17,11 @@ do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
zfs snap "$dataset@$new_bookmark"
|
zfs snap "$dataset@$new_bookmark"
|
||||||
|
|
||||||
if zfs list -t bookmark -H -o name | grep "^$dataset#$bookmark_prefix" | wc -l | grep -q "^0$"
|
if zfs list -t bookmark -H -o name | grep "^$dataset#$bookmark_prefix" | wc -l | grep -q "^0$"
|
||||||
then
|
then
|
||||||
echo "INITIAL BACKUP"
|
echo "INITIAL BACKUP"
|
||||||
# do in subshell, otherwise ctr+c will lead to 0 exitcode
|
# do in subshell, otherwise ctr+c will lead to 0 exitcode
|
||||||
$(zfs send -v "$dataset@$new_bookmark" | $ssh sudo zfs recv -F "$dataset" -o mountpoint=none)
|
$(zfs send -v "$dataset@$new_bookmark" | $ssh sudo zfs recv -F "$dataset" -o mountpoint=none)
|
||||||
else
|
else
|
||||||
echo "INCREMENTAL BACKUP"
|
echo "INCREMENTAL BACKUP"
|
||||||
|
@ -32,6 +32,19 @@ do
|
||||||
|
|
||||||
if [[ "$?" == "0" ]]
|
if [[ "$?" == "0" ]]
|
||||||
then
|
then
|
||||||
|
|
||||||
|
# delete old local bookmarks
|
||||||
|
for destroyable_bookmark in $(zfs list -t bookmark -H -o name "$dataset" | grep "^$dataset#$bookmark_prefix")
|
||||||
|
do
|
||||||
|
zfs destroy "$destroyable_bookmark"
|
||||||
|
done
|
||||||
|
|
||||||
|
# delete snapshots from bookmarks (except newest, even of not necessary; maybe for resuming tho)
|
||||||
|
for destroyable_snapshot in $($ssh sudo zfs list -t snapshot -H -o name "$dataset" | grep "^$dataset@$bookmark_prefix" | grep -v "$new_bookmark")
|
||||||
|
do
|
||||||
|
$ssh sudo zfs destroy "$destroyable_snapshot"
|
||||||
|
done
|
||||||
|
|
||||||
zfs bookmark "$dataset@$new_bookmark" "$dataset#$new_bookmark"
|
zfs bookmark "$dataset@$new_bookmark" "$dataset#$new_bookmark"
|
||||||
zfs destroy "$dataset@$new_bookmark"
|
zfs destroy "$dataset@$new_bookmark"
|
||||||
echo "SUCCESS $dataset"
|
echo "SUCCESS $dataset"
|
||||||
|
|
|
@ -54,11 +54,6 @@
|
||||||
'device': '/dev/disk/by-id/ata-TOSHIBA_MG06ACA10TE_61C0A1B1FKQE',
|
'device': '/dev/disk/by-id/ata-TOSHIBA_MG06ACA10TE_61C0A1B1FKQE',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'smartctl': {
|
|
||||||
'/dev/disk/by-id/ata-TOSHIBA_MG06ACA10TE_61C0A1B1FKQE': {
|
|
||||||
'apm': 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'zfs': {
|
'zfs': {
|
||||||
'pools': {
|
'pools': {
|
||||||
'tank': {
|
'tank': {
|
||||||
|
|
Loading…
Reference in a new issue