-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
raisin: implement remote zrepl sync w/ notes
- Loading branch information
1 parent
aae88a9
commit b8accd1
Showing
6 changed files
with
141 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ config, pkgs, lib, ... }: | ||
|
||
{ | ||
config = { | ||
networking.firewall.interfaces."tailscale0".allowedTCPPorts = [ | ||
8888 | ||
]; | ||
services.zrepl = { | ||
enable = true; | ||
settings = { | ||
jobs = [ | ||
{ | ||
name = "sink_origionraisin"; | ||
type = "sink"; | ||
root_fs = "orionraisinpool/backups"; | ||
serve = { | ||
type = "tcp"; | ||
listen = "100.112.194.64:8888"; | ||
listen_freebind = true; | ||
clients = { | ||
# TODO: source from data/ | ||
"100.109.239.83" = "zeph"; | ||
}; | ||
}; | ||
} | ||
]; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env nu | ||
|
||
let remote = $"cole@(tailscale ip --4 raisin)" | ||
scp ./zrepl-local-replication.nu $"($remote):/tmp/zrepl.nu | ||
ssh $"(remote)" "bash "-c" "chmod +x; /tmp/zrepl.nu raisin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,54 @@ | ||
#!/usr/bin/env nu | ||
|
||
let ssd = "usb-Realtek_RTL9210_NVME_012345678903-0:0" | ||
let hdr = "/home/cole/Sync/ORION_NVME_SSD/header.img" | ||
|
||
let luksdev = "orion" | ||
let backup_pool = "orionpool" | ||
let secret = "orion_luks" | ||
|
||
let pass = (prs show $secret | complete | get stdout | str trim) | ||
|
||
print -e "::: close backup pool" | ||
do -i { sudo sync; sync } | ||
do -i { sudo zpool export $backup_pool } | ||
do -i { sudo cryptsetup luksClose $luksdev } | ||
|
||
print -e "::: open backup pool" | ||
|
||
echo $pass | sudo cryptsetup luksOpen --header $hdr $"/dev/disk/by-id/($ssd)" $luksdev - | ||
sudo zpool import $backup_pool | ||
|
||
print -e "::: trigger push_to_orion" | ||
# TRIGGER ZREPL to copy | ||
sudo zrepl signal wakeup 'push_to_orion' | ||
|
||
# TODO: how to wait for replication to finish? | ||
|
||
print -e "" | ||
print -e "::: running, run these commands when it's done" | ||
print -e $"sudo sync; sudo zpool export ($backup_pool); sudo cryptsetup luksClose ($luksdev); sudo sync" | ||
|
||
sudo zrepl status | ||
def main [ job: string ] { | ||
let cfg = { | ||
job: "push_to_raisin" | ||
# use ssd+hdr on remote to unlock, bp to import | ||
remote: $"(tailscale ip --4 raisin)" | ||
ssd: "/dev/disk/by-id/usb-Realtek_RTL9210B-CG_012345678904-0:0" | ||
hdr: "/home/cole/SyncThingData/Sync/ORION_NVME_SSD/header_raisin.img" | ||
bp: "orionraisinpool" | ||
secret: "orionraisin_luks" | ||
} | ||
|
||
# if job == "push_to_orion" { | ||
# $cfg = { | ||
# job: "push_to_orion" | ||
# remote: "localhost" | ||
# ssd: "/dev/disk/by-id/usb-Realtek_RTL9210_NVME_012345678903-0:0" | ||
# hdr: "/home/cole/Sync/ORION_NVME_SSD/header.img" | ||
# bp: "orionpool" | ||
# secret: "orion_luks" | ||
# } | ||
# } | ||
|
||
print -e $cfg | ||
|
||
let luksdev = "orion" | ||
|
||
let pass = (prs show $cfg.secret | complete | get stdout | str trim) | ||
|
||
print -e "::: close backup pool" | ||
do -i { ssh $"($cfg.remote)" -- sudo sync; } | ||
do -i { ssh $"($cfg.remote)" -- sudo zpool export $cfg.bp } | ||
do -i { ssh $"($cfg.remote)" -- sudo cryptsetup luksClose $luksdev } | ||
|
||
print -e "::: open backup pool" | ||
|
||
# printf "%s" $pass out> /tmp/secret | ||
printf "%s" $pass | ssh $"($cfg.remote)" -- sudo cryptsetup luksOpen --header $cfg.hdr $cfg.ssd $luksdev - | ||
ssh $cfg.remote -- sudo zpool import $cfg.bp | ||
|
||
print -e $"::: trigger ($cfg.job)" | ||
# TRIGGER ZREPL to copy | ||
sudo zrepl signal wakeup $cfg.job | ||
|
||
# TODO: how to wait for replication to finish? | ||
print -e "" | ||
print -e "::: running, run these commands when it's done" | ||
print -e $"sudo sync" | ||
print -e $"sudo zpool export ($cfg.bp)" | ||
print -e $"sudo sync; sudo cryptsetup luksClose ($luksdev); sudo sync" | ||
|
||
sudo zrepl status | ||
} |