From 9a80c28b243c00d8637cec25246a018984fb7fae Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Thu, 8 Aug 2019 22:25:57 +0200 Subject: [PATCH] use a remote server --- bup-backup.hs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/bup-backup.hs b/bup-backup.hs index 3a728e4..d299bef 100755 --- a/bup-backup.hs +++ b/bup-backup.hs @@ -1,7 +1,7 @@ #!/usr/bin/env nix-script #!>haskell #! shell | bup git -#! env | BUP_DIR +#! env | BUP_DIR BUP_SRV #! haskell | shell-conduit filepath import Data.List (intersperse) @@ -9,6 +9,7 @@ import Data.Conduit.Shell import Data.Conduit.Shell.Segments (strings) import Data.Conduit.Shell.Variadic (variadicProcess) import System.FilePath +import System.Environment (lookupEnv) -- | regexs for excluded files @@ -21,25 +22,28 @@ excluded = intersperse "--exclude-rx" main :: IO () -main = run $ mapM_ backup =<< strings (bup "ls") +main = do + var <- lookupEnv "BUP_SRV" + case var of + Nothing -> run (echo "set the BUP_SRV variable to hostname:path") + Just server -> run $ + mapM_ (backup server) =<< strings (bup "ls" "-r" server) --- | Finds the path of a backup -findPath :: String -> Segment FilePath -findPath path = do - files <- strings (bup "ls" "-A" path) - if length files == 1 - then findPath (path head files) - else return $ "/" final path +findPath :: String -> String -> Segment FilePath +findPath server path = do + files <- strings (bup "ls" "-A" "-r" server path) + if length files /= 1 + then return ("/" final path) + else findPath server (path head files) where final = concat . drop 2 . splitPath --- | Runs the backup -backup :: String -> Segment () -backup name = do - path <- findPath (name "latest") +backup :: String -> String -> Segment () +backup server name = do + path <- findPath server (name "latest") proc "bup" ("index" : path : "--exclude-rx" : excluded) - bup "save" "-n" name path + bup "save" "-r" server "-n" name path -- | Fix for missing execs on NixOS