diff --git a/docs/restore-calibre.md b/docs/restore-calibre.md new file mode 100644 index 0000000..01aa71a --- /dev/null +++ b/docs/restore-calibre.md @@ -0,0 +1,23 @@ +# Restoring Calibre From Backup + +The `metadata.db` holds the library and `app.db` and `gdrive.db` contain the +web/account information. + +Place books directories in `/data/books/`. + +Place `metadata.db` in `/var/lib/calibre-web-db/`. + +Symlink `metadata.db` to the library: + +``` +sudo ln -s /var/lib/calibre-web-db/metadata.db /data/books/metadata.db +``` + +Place `app.db` and `gdrive.db` in `/var/lib/calibre-web/`. + +Restart Calibre: + +``` +sudo systemctl restart calibre-web.service +``` + diff --git a/docs/restore-nextcloud.md b/docs/restore-nextcloud.md index ad9381d..ff01b41 100644 --- a/docs/restore-nextcloud.md +++ b/docs/restore-nextcloud.md @@ -22,10 +22,10 @@ litestream restore -o nextcloud.db s3://noahmasur-backup.s3.us-west-002.backblaz Install Nextcloud. Then copy DB: ``` -sudo rm /var/lib/nextcloud/data/nextcloud.db* -sudo mv nextcloud.db /var/lib/nextcloud/data/ -sudo chown nextcloud:nextcloud /var/lib/nextcloud/data/nextcloud.db -sudo chmod 770 /var/lib/nextcloud/data/nextcloud.db +sudo rm /data/nextcloud/data/nextcloud.db* +sudo mv nextcloud.db /data/nextcloud/data/ +sudo chown nextcloud:nextcloud /data/nextcloud/data/nextcloud.db +sudo chmod 770 /data/nextcloud/data/nextcloud.db ``` Restart Nextcloud: @@ -37,7 +37,7 @@ sudo systemctl restart phpfpm-nextcloud.service Adjust Permissions and Directories: ``` -sudo mkdir /var/lib/nextcloud/data/noah/files -sudo chown nextcloud:nextcloud /var/lib/nextcloud/data/noah/files +sudo mkdir /data/nextcloud/data/noah/files +sudo chown nextcloud:nextcloud /data/nextcloud/data/noah/files ``` diff --git a/hosts/swan/default.nix b/hosts/swan/default.nix index c55b470..a9aa306 100644 --- a/hosts/swan/default.nix +++ b/hosts/swan/default.nix @@ -41,6 +41,7 @@ nixpkgs.lib.nixosSystem { caddy.enable = true; streamServer = "stream.masu.rs"; nextcloudServer = "cloud.masu.rs"; + bookServer = "books.masu.rs"; samba.enable = true; backup.s3 = { diff --git a/modules/nixos/services/calibre.nix b/modules/nixos/services/calibre.nix index c596303..feb9846 100644 --- a/modules/nixos/services/calibre.nix +++ b/modules/nixos/services/calibre.nix @@ -1,4 +1,10 @@ -{ config, pkgs, lib, ... }: { +{ config, pkgs, lib, ... }: + +let + + libraryPath = "/data/books"; + +in { options = { bookServer = lib.mkOption { @@ -6,6 +12,11 @@ description = "Hostname for Calibre library"; default = null; }; + backups.calibre = lib.mkOption { + type = lib.types.bool; + description = "Whether to backup Calibre library"; + default = true; + }; }; config = lib.mkIf (config.bookServer != null) { @@ -17,6 +28,7 @@ reverseProxyAuth.enable = false; enableBookConversion = true; enableBookUploading = true; + calibreLibrary = libraryPath; }; }; @@ -30,7 +42,7 @@ }]; # Run a backup on a schedule - systemd.timers.calibre-backup = { + systemd.timers.calibre-backup = lib.mkIf config.backups.calibre { timerConfig = { OnCalendar = "*-*-* 00:00:00"; # Once per day Unit = "calibre-backup.service"; @@ -39,24 +51,22 @@ }; # Backup Calibre data to object storage - systemd.services.calibre-backup = - let libraryPath = "/var/lib/calibre-web"; # Default location - in { - description = "Backup Calibre data"; - environment.AWS_ACCESS_KEY_ID = config.backup.s3.accessKeyId; - serviceConfig = { - Type = "oneshot"; - User = "calibre-web"; - Group = "backup"; - EnvironmentFile = config.secrets.backup.dest; - }; - script = '' - ${pkgs.awscli2}/bin/aws s3 sync \ - ${libraryPath}/ \ - s3://${config.backup.s3.bucket}/calibre/ \ - --endpoint-url=https://${config.backup.s3.endpoint} - ''; + systemd.services.calibre-backup = lib.mkIf config.backups.calibre { + description = "Backup Calibre data"; + environment.AWS_ACCESS_KEY_ID = config.backup.s3.accessKeyId; + serviceConfig = { + Type = "oneshot"; + User = "calibre-web"; + Group = "backup"; + EnvironmentFile = config.secrets.backup.dest; }; + script = '' + ${pkgs.awscli2}/bin/aws s3 sync \ + ${libraryPath}/ \ + s3://${config.backup.s3.bucket}/calibre/ \ + --endpoint-url=https://${config.backup.s3.endpoint} + ''; + }; };