Home : Fix backup.
This commit is contained in:
parent
40a295207f
commit
3ebfae082d
|
@ -1,10 +1,84 @@
|
||||||
{ pkgs, ... }: {
|
{ pkgs, style, util, ... } @args: let
|
||||||
|
bash = import ../../module/common/bash/Init.nix args;
|
||||||
|
script = pkgs.writeText "backupScript" ''
|
||||||
|
source ${bash.modules}
|
||||||
|
|
||||||
|
function report() {
|
||||||
|
echo "''${*}"
|
||||||
|
notify "''${*}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Define constants.
|
||||||
|
path_src="/storage/hot"
|
||||||
|
path_mount="/storage/cold_1"
|
||||||
|
path_backup="''${path_mount}/backup"
|
||||||
|
path_docker="''${path_backup}/home"
|
||||||
|
path_media="/storage/cold_1/media /storage/cold_2/media"
|
||||||
|
|
||||||
|
# Check if backup drive is mounted.
|
||||||
|
if [ ! -f "''${path_mount}"/.mount ]; then
|
||||||
|
report "Backup : ''${path_mount} not mounted!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if hot storage is mounted.
|
||||||
|
if [ ! -f "''${path_src}"/.mount ]; then
|
||||||
|
report "Backup : ''${path_src} not mounted!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cd to src storage.
|
||||||
|
cd "''${path_src}"
|
||||||
|
|
||||||
|
# Save media list.
|
||||||
|
find ''${path_media} -type d > ''${path_backup}/cold/ColdMedia.txt || report "Backup : Failed to save media list!"
|
||||||
|
cd ''${path_backup}/cold/
|
||||||
|
archive_fast ColdMedia.txt && rm ColdMedia.txt || report "Backup : Failed to archive media list!"
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Backup docker.
|
||||||
|
docker=$(archive_fast docker/)
|
||||||
|
bupsize=$(tdu ''${docker} | awk '{print $1}')
|
||||||
|
mv ''${docker} ''${path_docker}/ || report "Backup : Failed to save docker!"
|
||||||
|
|
||||||
|
# Backup some media.
|
||||||
|
cd ''${path_src}/media/
|
||||||
|
paper=$(archive_fast paper/)
|
||||||
|
mv ''${paper} ''${path_backup}/paper/ || report "Backup : Failed to save paper!"
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Prune media copies.
|
||||||
|
cd ''${path_backup}/paper/
|
||||||
|
archive_prune Paper 7
|
||||||
|
cd -
|
||||||
|
|
||||||
|
cd ''${path_backup}/cold/
|
||||||
|
archive_prune ColdMediaTxt 30
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Prune old Docker copies.
|
||||||
|
cd ''${path_docker}
|
||||||
|
archive_prune Docker 7
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Prune game saves.
|
||||||
|
cd "''${path_backup}/save/"
|
||||||
|
archive_prune
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Sync writes.
|
||||||
|
sync
|
||||||
|
|
||||||
|
# Notify completion & size.
|
||||||
|
notify_silent "Backup : Complete ''${bupsize}."
|
||||||
|
echo "Backup : Complete ''${bupsize}."
|
||||||
|
'';
|
||||||
|
in {
|
||||||
systemd.services.backup = {
|
systemd.services.backup = {
|
||||||
enable = true;
|
enable = true;
|
||||||
description = "Home system backup.";
|
description = "Home system backup.";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = ./bin/Backup;
|
|
||||||
};
|
};
|
||||||
path = with pkgs; [
|
path = with pkgs; [
|
||||||
bashInteractive
|
bashInteractive
|
||||||
|
@ -14,10 +88,9 @@
|
||||||
gawk
|
gawk
|
||||||
pv
|
pv
|
||||||
];
|
];
|
||||||
environment = {
|
script = ''
|
||||||
BASH_PATH = ../../module/common/bash;
|
${pkgs.bashInteractive}/bin/bash ${script}
|
||||||
};
|
'';
|
||||||
# wantedBy = [ "multi-user.target" ];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.timers.backup = {
|
systemd.timers.backup = {
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
{ pkgs, ... }: {
|
{ pkgs, style, util, ... } @args: let
|
||||||
|
bash = import ../../module/common/bash/Init.nix args;
|
||||||
|
script = ''
|
||||||
|
docker exec -u 33 cloud php -f /var/www/html/cron.php || notify 'Nextcloud : Failed to run cron.'
|
||||||
|
'';
|
||||||
|
in {
|
||||||
systemd.services.nextcloud = {
|
systemd.services.nextcloud = {
|
||||||
enable = true;
|
enable = true;
|
||||||
description = "Nextcloud worker.";
|
description = "Nextcloud worker.";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = ./bin/Nextcloud;
|
|
||||||
};
|
};
|
||||||
path = with pkgs; [
|
path = with pkgs; [
|
||||||
bashInteractive
|
bashInteractive
|
||||||
docker
|
docker
|
||||||
];
|
];
|
||||||
environment = {
|
script = ''
|
||||||
BASH_PATH = ../../module/common/bash;
|
${pkgs.bashInteractive}/bin/bash ${script}
|
||||||
};
|
'';
|
||||||
# wantedBy = [ "multi-user.target" ];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.timers.nextcloud = {
|
systemd.timers.nextcloud = {
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
{ pkgs, ... }: {
|
{ pkgs, ... }: let
|
||||||
|
script = ''
|
||||||
|
in="/storage/hot/docker/cloud/data/data/cakee/files/media/photo/"
|
||||||
|
out="/storage/cold_1/backup/tmp/photo/"
|
||||||
|
docker run --rm -v "''${in}":/in -v "''${out}":/out voronind.com/photoprocess:latest
|
||||||
|
'';
|
||||||
|
in {
|
||||||
systemd.services.photos_process = {
|
systemd.services.photos_process = {
|
||||||
enable = true;
|
enable = true;
|
||||||
description = "Process uploaded photos.";
|
description = "Process uploaded photos.";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = ./bin/PhotosProcess;
|
|
||||||
};
|
};
|
||||||
path = with pkgs; [
|
path = with pkgs; [
|
||||||
bashInteractive
|
|
||||||
docker
|
docker
|
||||||
];
|
];
|
||||||
# wantedBy = [ "multi-user.target" ];
|
script = script;
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.timers.photos_process = {
|
systemd.timers.photos_process = {
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
{ pkgs, ... }: {
|
{ pkgs, ... }: let
|
||||||
|
script = ''
|
||||||
|
music="/storage/hot/media/music/"
|
||||||
|
docker run --rm -v "''${music}":/music voronind.com/yamusic:latest
|
||||||
|
'';
|
||||||
|
in {
|
||||||
systemd.services.yandex_music = {
|
systemd.services.yandex_music = {
|
||||||
enable = true;
|
enable = true;
|
||||||
description = "Sync music from Yandex.Music.";
|
description = "Sync music from Yandex.Music.";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = ./bin/YandexMusic;
|
|
||||||
};
|
};
|
||||||
path = with pkgs; [
|
path = with pkgs; [
|
||||||
bashInteractive
|
|
||||||
docker
|
docker
|
||||||
];
|
];
|
||||||
# wantedBy = [ "multi-user.target" ];
|
script = script;
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.timers.yandex_music = {
|
systemd.timers.yandex_music = {
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Source modules.
|
|
||||||
for file in ${BASH_PATH}/module/*.sh; do
|
|
||||||
source "${file}"
|
|
||||||
done
|
|
||||||
|
|
||||||
function report() {
|
|
||||||
echo "${*}"
|
|
||||||
notify "${*}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Define constants.
|
|
||||||
path_src="/storage/hot"
|
|
||||||
path_mount="/storage/cold_1"
|
|
||||||
path_backup="${path_mount}/backup"
|
|
||||||
path_docker="${path_backup}/home"
|
|
||||||
path_media="/storage/cold_1/media /storage/cold_2/media"
|
|
||||||
|
|
||||||
# Check if backup drive is mounted.
|
|
||||||
if [ ! -f "${path_mount}"/.mount ]; then
|
|
||||||
report "Backup : ${path_mount} not mounted!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if hot storage is mounted.
|
|
||||||
if [ ! -f "${path_src}"/.mount ]; then
|
|
||||||
report "Backup : ${path_src} not mounted!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cd to src storage.
|
|
||||||
cd "${path_src}"
|
|
||||||
|
|
||||||
# Save media list.
|
|
||||||
find ${path_media} -type d > ${path_backup}/cold/ColdMedia.txt || report "Backup : Failed to save media list!"
|
|
||||||
cd ${path_backup}/cold/
|
|
||||||
archive_fast ColdMedia.txt && rm ColdMedia.txt || report "Backup : Failed to archive media list!"
|
|
||||||
cd -
|
|
||||||
|
|
||||||
# Backup docker.
|
|
||||||
docker=$(archive_fast docker/)
|
|
||||||
bupsize=$(tdu ${docker} | awk '{print $1}')
|
|
||||||
mv ${docker} ${path_docker}/ || report "Backup : Failed to save docker!"
|
|
||||||
|
|
||||||
# Backup some media.
|
|
||||||
cd ${path_src}/media/
|
|
||||||
paper=$(archive_fast paper/)
|
|
||||||
mv ${paper} ${path_backup}/paper/ || report "Backup : Failed to save paper!"
|
|
||||||
cd -
|
|
||||||
|
|
||||||
# Prune media copies.
|
|
||||||
cd ${path_backup}/paper/
|
|
||||||
archive_prune Paper 7
|
|
||||||
cd -
|
|
||||||
|
|
||||||
cd ${path_backup}/cold/
|
|
||||||
archive_prune ColdMediaTxt 30
|
|
||||||
cd -
|
|
||||||
|
|
||||||
# Prune old Docker copies.
|
|
||||||
cd ${path_docker}
|
|
||||||
archive_prune Docker 7
|
|
||||||
cd -
|
|
||||||
|
|
||||||
# Prune game saves.
|
|
||||||
cd "${path_backup}/save/"
|
|
||||||
archive_prune
|
|
||||||
cd -
|
|
||||||
|
|
||||||
# Sync writes.
|
|
||||||
sync
|
|
||||||
|
|
||||||
# Notify completion & size.
|
|
||||||
notify_silent "Backup : Complete ${bupsize}."
|
|
||||||
echo "Backup : Complete ${bupsize}."
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Source modules.
|
|
||||||
for file in ${BASH_PATH}/module/*.sh; do
|
|
||||||
source "${file}"
|
|
||||||
done
|
|
||||||
|
|
||||||
docker exec -u 33 cloud php -f /var/www/html/cron.php || notify 'Nextcloud : Failed to run cron.'
|
|
|
@ -1,6 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
in="/storage/hot/docker/cloud/data/data/cakee/files/media/photo/"
|
|
||||||
out="/storage/cold_1/backup/tmp/photo/"
|
|
||||||
|
|
||||||
docker run --rm -v "${in}":/in -v "${out}":/out voronind.com/photoprocess:latest
|
|
|
@ -1,5 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
music="/storage/hot/media/music/"
|
|
||||||
|
|
||||||
docker run --rm -v "${music}":/music voronind.com/yamusic:latest
|
|
|
@ -1,17 +1,19 @@
|
||||||
{ style, util, pkgs, ... } @args: let
|
{ style, util, pkgs, ... } @args: let
|
||||||
bashRc = pkgs.writeText "bashRc" (util.trimTabs (builtins.foldl' (acc: mod:
|
modules = pkgs.writeText "bashModules" (util.trimTabs (builtins.foldl' (acc: mod:
|
||||||
acc + (import mod args).text
|
acc + (import mod args).text
|
||||||
) "" (util.ls ./module)));
|
) "" (util.ls ./module)));
|
||||||
in {
|
in {
|
||||||
|
inherit modules;
|
||||||
|
|
||||||
config = util.trimTabs (''
|
config = util.trimTabs (''
|
||||||
# If not running interactively, don't do anything.
|
# If not running interactively, don't do anything.
|
||||||
[[ "$-" != *i* ]] && return
|
# [[ "$-" != *i* ]] && return
|
||||||
|
|
||||||
'') + builtins.readFile bashRc + util.trimTabs (''
|
'') + builtins.readFile modules + util.trimTabs (''
|
||||||
|
|
||||||
# Find all functions.
|
# Find all functions.
|
||||||
function find_function() {
|
function find_function() {
|
||||||
/usr/bin/env cat ${bashRc} | /usr/bin/env grep "^function.*()" | /usr/bin/env sed -e "s/^function //" -e "s/().*//"
|
/usr/bin/env cat ${modules} | /usr/bin/env grep "^function.*()" | /usr/bin/env sed -e "s/^function //" -e "s/().*//"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Export all functions.
|
# Export all functions.
|
||||||
|
|
Loading…
Reference in a new issue