bup-backup/bup-backup.hs

48 lines
1.1 KiB
Haskell
Raw Normal View History

2016-09-12 15:41:41 +02:00
#!/usr/bin/env nix-script
#!>haskell
#! shell | bup git
#! env | BUP_DIR
#! haskell | shell-conduit filepath
2019-01-31 18:20:33 +01:00
import Data.List (intersperse)
2016-09-12 15:41:41 +02:00
import Data.Conduit.Shell
import Data.Conduit.Shell.Segments (strings)
import Data.Conduit.Shell.Variadic (variadicProcess)
import System.FilePath
2019-01-31 18:20:33 +01:00
-- | regexs for excluded files
2016-09-12 15:41:41 +02:00
excluded :: [String]
2018-08-05 17:32:02 +02:00
excluded = intersperse "--exclude-rx"
[ "/home/rnhmjoj/game/"
, "/home/rnhmjoj/\\.cache/"
, "/unity3d/.+/.+/Unity/"
2016-09-12 15:41:41 +02:00
]
main :: IO ()
2019-01-31 18:20:33 +01:00
main = run $ mapM_ backup =<< strings (bup "ls")
2016-09-12 15:41:41 +02:00
2019-01-31 18:20:33 +01:00
-- | Finds the path of a backup
2016-09-12 15:41:41 +02:00
findPath :: String -> Segment FilePath
findPath path = do
2019-01-31 18:20:33 +01:00
files <- strings (bup "ls" "-A" path)
if length files == 1
then findPath (path </> head files)
else return $ "/" </> final path
2016-09-12 15:41:41 +02:00
where final = concat . drop 2 . splitPath
2019-01-31 18:20:33 +01:00
-- | Runs the backup
2016-09-12 15:41:41 +02:00
backup :: String -> Segment ()
backup name = do
path <- findPath (name </> "latest")
2018-08-05 17:32:02 +02:00
proc "bup" ("index" : path : "--exclude-rx" : excluded)
2016-09-12 15:41:41 +02:00
bup "save" "-n" name path
2019-01-31 18:20:33 +01:00
-- | Fix for missing execs on NixOS
2016-09-12 15:41:41 +02:00
bup :: ProcessType r => String -> r
bup = variadicProcess "bup"