diff --git a/systems/x86_64-linux/srv-prod-2/configuration.nix b/systems/x86_64-linux/srv-prod-2/configuration.nix index 9bd48a8..5978602 100644 --- a/systems/x86_64-linux/srv-prod-2/configuration.nix +++ b/systems/x86_64-linux/srv-prod-2/configuration.nix @@ -22,6 +22,8 @@ }; }; + users.users.nextcloud.openssh.authorizedKeys.keyFiles = [../srv-test-2/ssh_srv-test-2_ed25519_key.pub]; + # 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 diff --git a/systems/x86_64-linux/srv-test-2/configuration.nix b/systems/x86_64-linux/srv-test-2/configuration.nix index a7e1cee..ad9cfb6 100644 --- a/systems/x86_64-linux/srv-test-2/configuration.nix +++ b/systems/x86_64-linux/srv-test-2/configuration.nix @@ -1,6 +1,7 @@ {...}: { imports = [ ../../../modules + ./nextcloud-sync.nix ]; my = { diff --git a/systems/x86_64-linux/srv-test-2/nextcloud-sync.nix b/systems/x86_64-linux/srv-test-2/nextcloud-sync.nix new file mode 100644 index 0000000..81676be --- /dev/null +++ b/systems/x86_64-linux/srv-test-2/nextcloud-sync.nix @@ -0,0 +1,29 @@ +{ + config, + pkgs, + ... +}: let + nextcloud-sync = let + prodHost = config.my.homelab.srv-prod-2.ip; + nextcloudUser = "nextcloud"; + dataDir = "/var/lib/nextcloud/data"; + dbName = "nextcloud"; + dbDump = "/tmp/nextcloud-prod-dump.sql"; + in + pkgs.writeShellApplication { + name = "nextcloud-sync"; + runtimeInputs = [pkgs.rsync]; + text = '' + 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} + sudo -u ${nextcloudUser} psql --command="DROP DATABASE IF EXISTS ${dbName};" + sudo -u ${nextcloudUser} psql --command="CREATE DATABASE ${dbName} OWNER ${nextcloudUser};" + sudo -u ${nextcloudUser} psql --dbname=${dbName} --file=${dbDump} + rm -f ${dbDump} + ''; + }; +in { + environment.systemPackages = [nextcloud-sync]; +} diff --git a/systems/x86_64-linux/srv-test-2/ssh_srv-test-2_ed25519_key.pub b/systems/x86_64-linux/srv-test-2/ssh_srv-test-2_ed25519_key.pub new file mode 100644 index 0000000..8c997fa --- /dev/null +++ b/systems/x86_64-linux/srv-test-2/ssh_srv-test-2_ed25519_key.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE49YvpRLFot3FIVI16tmHEOxvO2LCKP2+40C08QT97d bene@pulse-14