move calibre books to zfs directory

This commit is contained in:
Noah Masur 2023-03-04 01:04:02 +00:00
parent 366a7f6157
commit 7ab78767d4
4 changed files with 59 additions and 25 deletions

23
docs/restore-calibre.md Normal file
View File

@ -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
```

View File

@ -22,10 +22,10 @@ litestream restore -o nextcloud.db s3://noahmasur-backup.s3.us-west-002.backblaz
Install Nextcloud. Then copy DB: Install Nextcloud. Then copy DB:
``` ```
sudo rm /var/lib/nextcloud/data/nextcloud.db* sudo rm /data/nextcloud/data/nextcloud.db*
sudo mv nextcloud.db /var/lib/nextcloud/data/ sudo mv nextcloud.db /data/nextcloud/data/
sudo chown nextcloud:nextcloud /var/lib/nextcloud/data/nextcloud.db sudo chown nextcloud:nextcloud /data/nextcloud/data/nextcloud.db
sudo chmod 770 /var/lib/nextcloud/data/nextcloud.db sudo chmod 770 /data/nextcloud/data/nextcloud.db
``` ```
Restart Nextcloud: Restart Nextcloud:
@ -37,7 +37,7 @@ sudo systemctl restart phpfpm-nextcloud.service
Adjust Permissions and Directories: Adjust Permissions and Directories:
``` ```
sudo mkdir /var/lib/nextcloud/data/noah/files sudo mkdir /data/nextcloud/data/noah/files
sudo chown nextcloud:nextcloud /var/lib/nextcloud/data/noah/files sudo chown nextcloud:nextcloud /data/nextcloud/data/noah/files
``` ```

View File

@ -41,6 +41,7 @@ nixpkgs.lib.nixosSystem {
caddy.enable = true; caddy.enable = true;
streamServer = "stream.masu.rs"; streamServer = "stream.masu.rs";
nextcloudServer = "cloud.masu.rs"; nextcloudServer = "cloud.masu.rs";
bookServer = "books.masu.rs";
samba.enable = true; samba.enable = true;
backup.s3 = { backup.s3 = {

View File

@ -1,4 +1,10 @@
{ config, pkgs, lib, ... }: { { config, pkgs, lib, ... }:
let
libraryPath = "/data/books";
in {
options = { options = {
bookServer = lib.mkOption { bookServer = lib.mkOption {
@ -6,6 +12,11 @@
description = "Hostname for Calibre library"; description = "Hostname for Calibre library";
default = null; default = null;
}; };
backups.calibre = lib.mkOption {
type = lib.types.bool;
description = "Whether to backup Calibre library";
default = true;
};
}; };
config = lib.mkIf (config.bookServer != null) { config = lib.mkIf (config.bookServer != null) {
@ -17,6 +28,7 @@
reverseProxyAuth.enable = false; reverseProxyAuth.enable = false;
enableBookConversion = true; enableBookConversion = true;
enableBookUploading = true; enableBookUploading = true;
calibreLibrary = libraryPath;
}; };
}; };
@ -30,7 +42,7 @@
}]; }];
# Run a backup on a schedule # Run a backup on a schedule
systemd.timers.calibre-backup = { systemd.timers.calibre-backup = lib.mkIf config.backups.calibre {
timerConfig = { timerConfig = {
OnCalendar = "*-*-* 00:00:00"; # Once per day OnCalendar = "*-*-* 00:00:00"; # Once per day
Unit = "calibre-backup.service"; Unit = "calibre-backup.service";
@ -39,24 +51,22 @@
}; };
# Backup Calibre data to object storage # Backup Calibre data to object storage
systemd.services.calibre-backup = systemd.services.calibre-backup = lib.mkIf config.backups.calibre {
let libraryPath = "/var/lib/calibre-web"; # Default location description = "Backup Calibre data";
in { environment.AWS_ACCESS_KEY_ID = config.backup.s3.accessKeyId;
description = "Backup Calibre data"; serviceConfig = {
environment.AWS_ACCESS_KEY_ID = config.backup.s3.accessKeyId; Type = "oneshot";
serviceConfig = { User = "calibre-web";
Type = "oneshot"; Group = "backup";
User = "calibre-web"; EnvironmentFile = config.secrets.backup.dest;
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}
'';
}; };
script = ''
${pkgs.awscli2}/bin/aws s3 sync \
${libraryPath}/ \
s3://${config.backup.s3.bucket}/calibre/ \
--endpoint-url=https://${config.backup.s3.endpoint}
'';
};
}; };