Compare commits

..

5 commits

Author SHA1 Message Date
3584c3c6fb added forgejo and gitea backups to script 2023-12-26 17:38:47 -08:00
1026fe3821 fixed gitea type 2023-12-26 15:27:05 -08:00
f33294fedc to string cast 2023-12-26 15:24:51 -08:00
9ff887a2e9 rebuild change 2023-12-26 15:21:19 -08:00
7b4802e989 added more backup options 2023-12-26 15:17:29 -08:00
3 changed files with 102 additions and 16 deletions

View file

@ -24,7 +24,19 @@
tmp_mount_point = /Aurora/backup_drive_mount_point;
backup1_drive_label = "AlaskaBackup";
vaultwarden = {
enable = true;
backup_dir = "/Aurora/Backups/Vaultwarden";
};
forgejo = {
enable = true;
backups_dir = "/Aurora/Backups/Forgejo";
save_old_count = 5;
};
nextcloud = {
enable = true;
root_dir = /Aurora/nextcloud;
db_server = "127.0.0.1";
db_name = "nextcloud";

View file

@ -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 = {
enable = lib.mkEnableOption (lib.mkDoc "Back up nextcloud instance");
root_dir = lib.mkOption {
type = lib.types.path;
default = /Aurora/nextcloud;
@ -91,8 +122,10 @@ in
description = "Alaska Nightly Backup Service";
onFailure = [ "alaska_backup_script_onfail.service" ];
path = with pkgs; [
gawk
config.services.nextcloud.occ
config.services.postgresql.package
config.services.gitea.package
rsync
mount
umount
@ -106,15 +139,18 @@ in
echo "Mounting the external backup drive"
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
if [ "${builtins.toString cfg.nextcloud.enable}" = "1" ]; 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"
mkdir -p ${builtins.toString cfg.tmp_mount_point}/nextcloud/db_backups
password='cat ${builtins.toString cfg.nextcloud.db_passfile}'
PGPASSWORD="$password" pg_dump \
${builtins.toString cfg.nextcloud.db_name} -h ${builtins.toString cfg.nextcloud.db_server} \
-U ${builtins.toString cfg.nextcloud.db_user} \
-f ${builtins.toString cfg.tmp_mount_point}/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak
-f ${builtins.toString cfg.tmp_mount_point}/nextcloud/db_backups/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak
echo "Backing up the nextcloud files"
# -a archive | -v verbose
@ -122,8 +158,39 @@ in
${builtins.toString cfg.tmp_mount_point}/nextcloud \
--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
fi
#---- END NEXTCLOUD
#---- BEGIN FORGEJO
if [ "${builtins.toString cfg.forgejo.enable}" = "1" ]; 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} \
| gawk '{print $2}' \
| xargs rm || true
echo "Copying Forgejo backup"
latest_backup=$(find ${builtins.toString cfg.forgejo.backups_dir} -type f -printf '%T+ %p\n' \
| grep .${builtins.toString config.services.gitea.dump.type} \
| sort | head -n 1 | gawk '{print $2}')
cp "$latest_backup" ${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}\
| gawk '{print $2}'\
| xargs rm || true
fi
#----- END FORGEJO
#----- BEGIN VAULTWARDEN
if [ "${builtins.toString cfg.vaultwarden.enable}" = "1" ]; then
rsync -av ${cfg.vaultwarden.backup_dir} ${builtins.toString cfg.tmp_mount_point}
fi
#----- END VAULTWARDEN
echo "Unmounting the external drive"
umount ${builtins.toString cfg.tmp_mount_point}
@ -131,7 +198,7 @@ in
echo "Job completed"
# "
'';
startAt = "Sun 14:00:00";
startAt = "Sun 02:00:00"; # equvalent of OnCalendar
# serviceConfig = {
# Type = "oneshot";

View file

@ -17,6 +17,13 @@ in
customDir = "/Aurora/Forgejo/custom";
appName = "Nickiel's Repos";
dump = {
enable = true;
backupDir = "/Aurora/Backups/Forgejo";
# file = "gitea-backup.zip";
interval = "01:25";
};
settings = {
"ui" = {