mirror of
https://github.com/Nickiel12/nicks-nix-config.git
synced 2024-11-22 20:59:32 -08:00
added more backup options
This commit is contained in:
parent
9dbf847155
commit
7b4802e989
3 changed files with 100 additions and 16 deletions
|
@ -24,7 +24,19 @@
|
||||||
tmp_mount_point = /Aurora/backup_drive_mount_point;
|
tmp_mount_point = /Aurora/backup_drive_mount_point;
|
||||||
backup1_drive_label = "AlaskaBackup";
|
backup1_drive_label = "AlaskaBackup";
|
||||||
|
|
||||||
|
vaultwarden = {
|
||||||
|
enable = false;
|
||||||
|
backup_dir = "/Aurora/Backups/Vaultwarden";
|
||||||
|
};
|
||||||
|
|
||||||
|
forgejo = {
|
||||||
|
enable = true;
|
||||||
|
backups_dir = "/Aurora/Backups/Forgejo";
|
||||||
|
save_old_count = 5;
|
||||||
|
};
|
||||||
|
|
||||||
nextcloud = {
|
nextcloud = {
|
||||||
|
enable = false;
|
||||||
root_dir = /Aurora/nextcloud;
|
root_dir = /Aurora/nextcloud;
|
||||||
db_server = "127.0.0.1";
|
db_server = "127.0.0.1";
|
||||||
db_name = "nextcloud";
|
db_name = "nextcloud";
|
||||||
|
|
|
@ -32,8 +32,39 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
forgejo = {
|
||||||
|
enable = lib.mkEnableOption (lib.mdDoc "Back up Forgejo instance");
|
||||||
|
|
||||||
|
backups_dir = lib.mkOption {
|
||||||
|
type = lib.types.path;
|
||||||
|
default = "/Aurora/Backups/Forgejo";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The path where Gitea/Forgejo backups are dumped
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
save_old_count = lib.mkOption {
|
||||||
|
type = lib.types.int;
|
||||||
|
default = 3;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The number of backups to save before deleting the oldest
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
vaultwarden = {
|
||||||
|
enable = lib.mkEnableOption (lib.mdDoc "Back up vault warden instance");
|
||||||
|
|
||||||
|
backup_dir = lib.mkOption {
|
||||||
|
type = lib.types.path;
|
||||||
|
default = "/Aurora/Backups/Vaultwarden";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The path where vaultwarden backups are put
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
nextcloud = {
|
nextcloud = {
|
||||||
|
enable = lib.mkEnableOption (lib.mkDoc "Back up nextcloud instance");
|
||||||
root_dir = lib.mkOption {
|
root_dir = lib.mkOption {
|
||||||
type = lib.types.path;
|
type = lib.types.path;
|
||||||
default = /Aurora/nextcloud;
|
default = /Aurora/nextcloud;
|
||||||
|
@ -93,6 +124,7 @@ in
|
||||||
path = with pkgs; [
|
path = with pkgs; [
|
||||||
config.services.nextcloud.occ
|
config.services.nextcloud.occ
|
||||||
config.services.postgresql.package
|
config.services.postgresql.package
|
||||||
|
config.services.gitea.package
|
||||||
rsync
|
rsync
|
||||||
mount
|
mount
|
||||||
umount
|
umount
|
||||||
|
@ -106,24 +138,57 @@ in
|
||||||
echo "Mounting the external backup drive"
|
echo "Mounting the external backup drive"
|
||||||
mount /dev/disk/by-label/${cfg.backup1_drive_label} ${builtins.toString cfg.tmp_mount_point} -t ntfs3
|
mount /dev/disk/by-label/${cfg.backup1_drive_label} ${builtins.toString cfg.tmp_mount_point} -t ntfs3
|
||||||
|
|
||||||
echo "Puttin nextcloud into maintenance mode so that changes cannot happen during the backup"
|
#------ BEGIN NEXTCLOUD
|
||||||
nextcloud-occ maintenance:mode --on
|
if [ "${cfg.nextcloud.enable}" = true ]; then
|
||||||
|
echo "Putting nextcloud into maintenance mode so that changes cannot happen during the backup"
|
||||||
|
nextcloud-occ maintenance:mode --on
|
||||||
|
|
||||||
echo "Backing up the nextcloud database"
|
echo "Backing up the nextcloud database"
|
||||||
password='cat ${builtins.toString cfg.nextcloud.db_passfile}'
|
mkdir -p ${builtins.toString cfg.tmp_mount_point}/nextcloud/db_backups
|
||||||
PGPASSWORD="$password" pg_dump \
|
password='cat ${builtins.toString cfg.nextcloud.db_passfile}'
|
||||||
${builtins.toString cfg.nextcloud.db_name} -h ${builtins.toString cfg.nextcloud.db_server} \
|
PGPASSWORD="$password" pg_dump \
|
||||||
-U ${builtins.toString cfg.nextcloud.db_user} \
|
${builtins.toString cfg.nextcloud.db_name} -h ${builtins.toString cfg.nextcloud.db_server} \
|
||||||
-f ${builtins.toString cfg.tmp_mount_point}/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak
|
-U ${builtins.toString cfg.nextcloud.db_user} \
|
||||||
|
-f ${builtins.toString cfg.tmp_mount_point}/nextcloud/db_backups/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak
|
||||||
|
|
||||||
echo "Backing up the nextcloud files"
|
echo "Backing up the nextcloud files"
|
||||||
# -a archive | -v verbose
|
# -a archive | -v verbose
|
||||||
rsync -av ${builtins.toString cfg.nextcloud.root_dir} \
|
rsync -av ${builtins.toString cfg.nextcloud.root_dir} \
|
||||||
${builtins.toString cfg.tmp_mount_point}/nextcloud \
|
${builtins.toString cfg.tmp_mount_point}/nextcloud \
|
||||||
--exclude '*/appdata_*' --exclude "*/files_trashbin/*" --exclude "*/files_versions/*"
|
--exclude '*/appdata_*' --exclude "*/files_trashbin/*" --exclude "*/files_versions/*"
|
||||||
|
|
||||||
echo "Get nextcloud out of maintenance mode so that normal operations can resume"
|
echo "Ending nextcloud maintenance mode so that normal operations can resume"
|
||||||
nextcloud-occ maintenance:mode --off
|
nextcloud-occ maintenance:mode --off
|
||||||
|
fi
|
||||||
|
#---- END NEXTCLOUD
|
||||||
|
|
||||||
|
#---- BEGIN FORGEJO
|
||||||
|
if [ "${cfg.forgejo.enable}" = true ]; then
|
||||||
|
echo "deleting old Forgejo backups"
|
||||||
|
find ${builtins.toString cfg.tmp_mount_point}/Forgejo -type f -printf '%T+ %p\n'\
|
||||||
|
| sort | head -n -${builtins.toString cfg.forgejo.save_old_count}\
|
||||||
|
| awk '{print $2}'\
|
||||||
|
| xargs rm
|
||||||
|
|
||||||
|
echo "Copying Forgejo backup"
|
||||||
|
cp `find ${builtins.toString cfg.forgejo.backups_dir} -type f -printf '%T+ %p\n'\
|
||||||
|
| grep *.${builtins.toString config.services.gitea.type}
|
||||||
|
| sort | head -n 1 | awk '{print $2}'` ${builtins.toString cfg.tmp_mount_point}/Forgejo
|
||||||
|
|
||||||
|
echo "Clearing old Forgejo backups"
|
||||||
|
find ${builtins.toString cfg.forgejo.backups_dir} -type f -printf '%T+ %p\n'\
|
||||||
|
| sort | head -n -${builtins.toString cfg.forgejo.save_old_count}\
|
||||||
|
| awk '{print $2}'\
|
||||||
|
| xargs rm
|
||||||
|
fi
|
||||||
|
#----- END FORGEJO
|
||||||
|
|
||||||
|
#----- BEGIN VAULTWARDEN
|
||||||
|
if [ "${cfg.vaultwarden.enable}" = true]; then
|
||||||
|
rsync -av ${cfg.vaultwarden.backup_dir} ${builtins.toString cfg.tmp_mount_point}/Vaultwarden
|
||||||
|
|
||||||
|
fi
|
||||||
|
#----- END VAULTWARDEN
|
||||||
|
|
||||||
echo "Unmounting the external drive"
|
echo "Unmounting the external drive"
|
||||||
umount ${builtins.toString cfg.tmp_mount_point}
|
umount ${builtins.toString cfg.tmp_mount_point}
|
||||||
|
@ -131,7 +196,7 @@ in
|
||||||
echo "Job completed"
|
echo "Job completed"
|
||||||
# "
|
# "
|
||||||
'';
|
'';
|
||||||
startAt = "Sun 14:00:00";
|
startAt = "Sun 02:00:00"; # equvalent of OnCalendar
|
||||||
|
|
||||||
# serviceConfig = {
|
# serviceConfig = {
|
||||||
# Type = "oneshot";
|
# Type = "oneshot";
|
||||||
|
|
|
@ -17,6 +17,13 @@ in
|
||||||
customDir = "/Aurora/Forgejo/custom";
|
customDir = "/Aurora/Forgejo/custom";
|
||||||
appName = "Nickiel's Repos";
|
appName = "Nickiel's Repos";
|
||||||
|
|
||||||
|
dump = {
|
||||||
|
enable = true;
|
||||||
|
backupDir = "/Aurora/Backups/Forgejo";
|
||||||
|
# file = "gitea-backup.zip";
|
||||||
|
interval = "01:25";
|
||||||
|
};
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
|
|
||||||
"ui" = {
|
"ui" = {
|
||||||
|
|
Loading…
Reference in a new issue