Commit 0b533ed7 authored by Yuanle Song's avatar Yuanle Song
Browse files

update doc; added appendWhen;

fixed local.exclude typo
parent d8cf9beb
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -18,14 +18,12 @@ let ExitTimeout = 2

type CLIArguments =
    | DryRun
    | Cron
    | Target of backupTarget: string
with
    interface IArgParserTemplate with
        member s.Usage =
            match s with
            | DryRun _ -> "only show what will be done, do not transfer any file"
            | Cron _ -> "run in cron mode, do not ask user any questions"
            | Target _ -> "rsync target, could be local dir or remote ssh dir"

type Logger() =
@@ -85,12 +83,19 @@ let runtimeDir = appDataLocalDir

let isLocalTarget (target: string) = target.StartsWith "/"

// generate mbackup.list file
let generateMbackupList =
    // TODO run make to update mbackup.list. only update if source file have changed.
    null

// append string s to list if pred is true
let appendWhen (pred: bool) (lst: string list) (s: string) = if pred then List.append lst [s] else lst

[<EntryPoint>]
let main argv =
    let errorHandler = ProcessExiter(colorizer = function ErrorCode.HelpText -> None | _ -> Some ConsoleColor.Red)
    let parser = ArgumentParser.Create<CLIArguments>(programName = "mbackup.exe", errorHandler = errorHandler)
    let results = parser.Parse argv
    let cron = results.Contains Cron
    let dryRun = results.Contains DryRun

    let logger = Logger()
@@ -99,14 +104,17 @@ let main argv =
    logger.Info "runtimeDir=%s" runtimeDir

    let rsyncCmd: string list = []
    let rsyncCmd = if dryRun then List.append rsyncCmd ["--dry-run"] else rsyncCmd
    let rsyncCmd = appendWhen dryRun rsyncCmd "--dry-run"
    let rsyncCmd = List.append rsyncCmd ("-h --stats -air --delete --delete-excluded --ignore-missing-args".Split [|' '|] |> Array.toList)
    let mbackupFile = runtimeDir + "mbackup.list"
    generateMbackupList |> ignore
    let rsyncCmd = List.append rsyncCmd [sprintf "--files-from=%s" mbackupFile]

    let excludeFile = userConfigDir + "mbackup-default.exclude"
    let rsyncCmd = List.append rsyncCmd [sprintf "--exclude-from=%s" excludeFile]
    let localExcludeFile = userConfigDir + "local.list"
    let rsyncCmd = if IO.File.Exists localExcludeFile then List.append rsyncCmd [sprintf "--exclude-from=%s" localExcludeFile] else rsyncCmd
    let localExcludeFile = userConfigDir + "local.exclude"
    let rsyncCmd = appendWhen (IO.File.Exists localExcludeFile) rsyncCmd (sprintf "--exclude-from=%s" localExcludeFile)

    let localLogFile = runtimeDir + "mbackup.log"
    let rsyncCmd = List.append rsyncCmd [sprintf "--log-file=%s" localLogFile]

@@ -135,7 +143,7 @@ let main argv =
          let rsyncExe = "D:\\downloads\\apps\\rsync-w64-3.1.3-2-standalone\\usr\\bin\\rsync.exe"
          let echoExe = "C:\\Program Files\\Git\\usr\\bin\\echo.exe"
          let proc = Process.Start(echoExe, rsyncArgs)
          logger.Info "%s" (rsyncExe + rsyncArgs)
          logger.Info "%s" (rsyncExe + " " + rsyncArgs)
          if proc.WaitForExit Int32.MaxValue then
            proc.ExitCode
          else
+10 −0
Original line number Diff line number Diff line
@@ -43,6 +43,16 @@ Time-stamp: <2019-11-12>
* later                                                               :entry:
* current                                                             :entry:
** 
** 2019-11-13 next todos
- fix TODOs in F# code
- add rsync command and arguments for running in windows.
  i.e. -e etc.
- test param parsing is working.
  command line param > env var > mbackup default value.
  support --node-name param.
- test run in console and scheduled task.
- create an installer. The installer should add scheduled task on install and
  delete scheduled task on removal.
** 2019-11-12 make code work in a specific dir. then create an installer.
- install to %programfiles%
- config is saved to %appdata% roaming dir.