added mkbackup command, leverages sshfs to quickly backup files to xenon
This commit is contained in:
30
modules/home/scripts/commands/mkbackup.nix
Normal file
30
modules/home/scripts/commands/mkbackup.nix
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{ pkgs }:
|
||||||
|
|
||||||
|
pkgs.writeShellScriptBin "mkbackup" ''
|
||||||
|
if ! findmnt | grep share; then
|
||||||
|
echo "Mounting shared filesystem..."
|
||||||
|
if ! sshfs pagedmov@192.168.1.200:/home/pagedmov/share $HOME/share; then
|
||||||
|
echo "failed to mount shared storage to $HOME/share" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Done"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Copying files..."
|
||||||
|
if printf '%s\0' "$@" | xargs -0 -I {} cp {} -v "$HOME/share"; then
|
||||||
|
echo "Done"
|
||||||
|
else
|
||||||
|
echo "Failed to copy files to shared directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Moving files to backup folder on serverside..."
|
||||||
|
if ssh pagedmov@192.168.1.200 "IFS=' ' read -rA files <<< \"$@\"; for file in \''${files[@]}; do echo -n \"\$(whoami)@\$(hostname): \"; mv -v ~/share/\"\$file\" ~/backup; done"; then
|
||||||
|
echo "Backup completed."
|
||||||
|
umount $HOME/share
|
||||||
|
else
|
||||||
|
echo "Failed to move files on serverside. Unmounting shared filesystem."
|
||||||
|
umount $HOME/share
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
''
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
invoke = import ./commands/invoke.nix { inherit self pkgs; };
|
invoke = import ./commands/invoke.nix { inherit self pkgs; };
|
||||||
splash = import ./commands/splash.nix { inherit self pkgs; };
|
splash = import ./commands/splash.nix { inherit self pkgs; };
|
||||||
runbg = import ./commands/runbg.nix { inherit self pkgs; };
|
runbg = import ./commands/runbg.nix { inherit self pkgs; };
|
||||||
|
mkbackup = import ./commands/mkbackup.nix { inherit pkgs; };
|
||||||
garbage-collect = import ./nix/garbage-collect.nix { inherit self pkgs; };
|
garbage-collect = import ./nix/garbage-collect.nix { inherit self pkgs; };
|
||||||
nsp = import ./nix/nsp.nix { inherit self pkgs; };
|
nsp = import ./nix/nsp.nix { inherit self pkgs; };
|
||||||
scheck = import ./wm-controls/s_check.nix { inherit self pkgs; };
|
scheck = import ./wm-controls/s_check.nix { inherit self pkgs; };
|
||||||
@@ -41,6 +42,8 @@ in {
|
|||||||
lib.mkEnableOption "Enables all Nix shortcut scripts";
|
lib.mkEnableOption "Enables all Nix shortcut scripts";
|
||||||
|
|
||||||
# Individual options using scriptOverride or mkEnableOption directly
|
# Individual options using scriptOverride or mkEnableOption directly
|
||||||
|
movScripts.commandScripts.mkbackup.enable =
|
||||||
|
scriptOverride "Enables the mkbackup command" "commandScripts" "mkbackup";
|
||||||
movScripts.commandScripts.invoke.enable =
|
movScripts.commandScripts.invoke.enable =
|
||||||
scriptOverride "Enables the invoke command" "commandScripts" "invoke";
|
scriptOverride "Enables the invoke command" "commandScripts" "invoke";
|
||||||
movScripts.commandScripts.runbg.enable =
|
movScripts.commandScripts.runbg.enable =
|
||||||
@@ -76,6 +79,7 @@ in {
|
|||||||
config = lib.mkIf config.movScripts.enable {
|
config = lib.mkIf config.movScripts.enable {
|
||||||
home.packages = lib.optionals config.movScripts.commandScripts.invoke.enable [ invoke ]
|
home.packages = lib.optionals config.movScripts.commandScripts.invoke.enable [ invoke ]
|
||||||
++ lib.optionals config.movScripts.commandScripts.runbg.enable [ runbg ]
|
++ lib.optionals config.movScripts.commandScripts.runbg.enable [ runbg ]
|
||||||
|
++ lib.optionals config.movScripts.commandScripts.mkbackup.enable [ mkbackup ]
|
||||||
++ lib.optionals config.movScripts.commandScripts.splash.enable [ splash ]
|
++ lib.optionals config.movScripts.commandScripts.splash.enable [ splash ]
|
||||||
++ lib.optionals config.movScripts.commandScripts.toolbelt.enable [ toolbelt ]
|
++ lib.optionals config.movScripts.commandScripts.toolbelt.enable [ toolbelt ]
|
||||||
++ lib.optionals config.movScripts.commandScripts.viconf.enable [ viconf ]
|
++ lib.optionals config.movScripts.commandScripts.viconf.enable [ viconf ]
|
||||||
|
|||||||
Reference in New Issue
Block a user