Skip to content

Commit

Permalink
hosts (srv-test-2): Fix nextcloud-sync script
Browse files Browse the repository at this point in the history
The script was trying to connect via srv-prod-2's IP address but the ssh
config uses 'srv-prod-2' as host identifier. After this change, the
script uses the host identifier from the ssh configuration and also does
no longer pass the user name to connect with, because that's also
configured in ssh config.
  • Loading branch information
britter committed Dec 4, 2024
1 parent 519a2ef commit 3992318
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 1 addition & 8 deletions systems/x86_64-linux/srv-test-2/configuration.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{config, ...}: {
{...}: {
imports = [
../../../modules
./nextcloud-sync.nix
Expand All @@ -23,13 +23,6 @@
};
};

programs.ssh.extraConfig = ''
Host srv-prod-2
HostName ${config.my.homelab.srv-prod-2.ip}
User nextcloud
IdentityFile /etc/ssh/ssh_host_ed25519_key
IdentitiesOnly yes
'';
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. It‘s perfectly fine and recommended to leave
Expand Down
18 changes: 13 additions & 5 deletions systems/x86_64-linux/srv-test-2/nextcloud-sync.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
pkgs,
...
}: let
prodHost = "srv-prod-2";
nextcloud-sync = let
prodHost = config.my.homelab.srv-prod-2.ip;
nextcloudUser = "nextcloud";
dataDir = "/var/lib/nextcloud/data";
dbName = "nextcloud";
Expand All @@ -15,10 +15,10 @@
runtimeInputs = [pkgs.rsync config.services.nextcloud.occ];
text = ''
nextcloud-occ maintenance:mode --on
ssh ${nextcloudUser}@${prodHost} "pg_dump --username=${nextcloudUser} --file=${dbDump} ${dbName}"
scp ${nextcloudUser}@${prodHost}:${dbDump} ${dbDump}
ssh ${nextcloudUser}@${prodHost} "rm -f ${dbDump}"
rsync -avz --delete ${nextcloudUser}@${prodHost}:${dataDir} ${dataDir}
ssh ${prodHost} "pg_dump --username=${nextcloudUser} --file=${dbDump} ${dbName}"
scp ${prodHost}:${dbDump} ${dbDump}
ssh ${prodHost} "rm -f ${dbDump}"
rsync -avz --delete ${prodHost}:${dataDir} ${dataDir}
sudo -u postgres psql --command="DROP DATABASE IF EXISTS ${dbName};"
sudo -u postgres psql --command="CREATE DATABASE ${dbName} OWNER ${nextcloudUser};"
sudo -u ${nextcloudUser} psql --dbname=${dbName} --file=${dbDump}
Expand All @@ -28,4 +28,12 @@
};
in {
environment.systemPackages = [nextcloud-sync];

programs.ssh.extraConfig = ''
Host ${prodHost}
HostName ${config.my.homelab.srv-prod-2.ip}
User nextcloud
IdentityFile /etc/ssh/ssh_host_ed25519_key
IdentitiesOnly yes
'';
}

0 comments on commit 3992318

Please sign in to comment.