-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hosts (srv-test-2): Add NextCloud synx script (#78)
The script uses ssh, scp, and rsync to connect to and transfer data from srv-prod-2. Data being present on srv-test-2 NextCloud is dropped in the process.
- Loading branch information
Showing
4 changed files
with
33 additions
and
0 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{...}: { | ||
imports = [ | ||
../../../modules | ||
./nextcloud-sync.nix | ||
]; | ||
|
||
my = { | ||
|
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,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]; | ||
} |
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 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE49YvpRLFot3FIVI16tmHEOxvO2LCKP2+40C08QT97d bene@pulse-14 |