use a remote server
This commit is contained in:
parent
3e04fe10bf
commit
9a80c28b24
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user