Loading Program.fs +17 −16 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ type CLIArguments = | Remote_User of remoteUser: string | [<AltCommandLine("-i")>] Itemize_Changes | Node_Name of nodeName: string | Ssh_Key of sshKeyFilename: string with interface IArgParserTemplate with member s.Usage = Loading @@ -38,6 +39,7 @@ with | Remote_User _ -> "remote linux user to own the backup files" | Itemize_Changes _ -> "add -i option to rsync" | Node_Name _ -> "local node's name, used in remote logging" | Ssh_Key _ -> "ssh private key, used when backup to remote ssh node" type Logger() = let mutable level = Logger.DEBUG Loading Loading @@ -105,12 +107,18 @@ let EnsureWinDir (path: string) = if path.EndsWith "\\" then path else path + "\ let appDataRoamingDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) |> ToMingwPath |> EnsureDir let programDataDirWin = GetEnv "PROGRAMDATA" |> EnsureWinDir let programDataDir = ToMingwPath programDataDirWin let appDataLocalDirWin = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) |> EnsureDir let appDataLocalDirWin = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) |> EnsureWinDir let appDataLocalDir = appDataLocalDirWin |> ToMingwPath let mbackupInstallDirWin = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) |> EnsureDir |> fun s -> s + "mbackup" let mbackupInstallDir = mbackupInstallDirWin |> ToMingwPath let userHomeWin = GetEnvDefault "HOME" (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) |> EnsureWinDir let userHome = userHomeWin |> ToMingwPath //let userConfigDir = appDataRoamingDir + "mbackup/" let userConfigDirWin = programDataDirWin + "mbackup\\" let userConfigDir = programDataDir + "mbackup/" Loading Loading @@ -142,7 +150,6 @@ let expandUserFile (fn: string) = if fn.StartsWith("/") then fn else let userHome = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) |> ToMingwPath |> EnsureDir userHome + fn // generate mbackup.list file Loading @@ -159,10 +166,10 @@ let generateMbackupList (logger: Logger) = let readMbackupListFile fn = File.ReadAllLines(fn) |> dropEmptyLinesAndComments try let defaultListLines = readMbackupListFile mbackupDefaultList let defaultListLines = readMbackupListFile mbackupDefaultList |> Seq.map ToMingwPath let localListLinesMaybe = try let lines = readMbackupListFile mbackupLocalList let lines = readMbackupListFile mbackupLocalList |> Seq.map ToMingwPath (true, lines) with | :? System.IO.FileNotFoundException -> Loading Loading @@ -199,8 +206,8 @@ let main argv = let logger = Logger() logger.Info "userConfigDir=%s" userConfigDir logger.Info "runtimeDir=%s" runtimeDir logger.Info "using user config dir: %s" userConfigDirWin logger.Info "using runtime dir: %s" runtimeDirWin let rsyncCmd: string list = [] let rsyncCmd = appendWhen dryRun rsyncCmd "--dry-run" Loading @@ -224,8 +231,8 @@ let main argv = let mbackupInstallDirWinTest = "D:\\downloads\\apps\\mbackupTest\\" let mbackupInstallDirTest = mbackupInstallDirWinTest |> ToMingwPath |> EnsureDir let sshExeFile = mbackupInstallDirTest + "rsync-w64/usr/bin/ssh.exe" let sshConfigFile = userConfigDir + "ssh_config" let sshPrivateKeyFile = userConfigDir + "ssh_id_rsa" let sshConfigFile = userHome + ".ssh/config" let sshPrivateKeyFile = results.GetResult(Ssh_Key, defaultValue = userHome + ".ssh/id_rsa") |> ToMingwPath let rsyncCmd = List.append rsyncCmd [sprintf "-e \"%s -F %s -i %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\"" sshExeFile sshConfigFile sshPrivateKeyFile] let backupTarget = results.GetResult (Target, defaultValue = Environment.GetEnvironmentVariable "TARGET") Loading @@ -238,13 +245,7 @@ let main argv = let rsyncCmd = if not (isLocalTarget backupTarget) then let nodeName = match results.GetResult Node_Name with | null -> match GetEnv "NODE_NAME" with | null -> Net.Dns.GetHostName() | X -> X | X -> X let nodeName = results.GetResult(Node_Name, defaultValue = Net.Dns.GetHostName()) let remoteLogFile = sprintf "/var/log/mbackup/%s.log" nodeName let remoteUser = results.GetResult (Remote_User, defaultValue = Environment.UserName) let rsyncCmd = List.append rsyncCmd [sprintf "--remote-option=--log-file=%s" remoteLogFile] Loading mbackup-config/mbackup-default.list +3 −3 Original line number Diff line number Diff line # dirs to backup /cygdrive/c/ProgramData/mbackup /cygdrive/c/path/to/dir /cygdrive/d/path/to/dir C:\ProgramData\mbackup C:\path\to\dir D:\path\to\dir operational +11 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,15 @@ dotnet run -- --dry-run --itemize-changes --target d:\backup dotnet run -- -n -i --target d:\backup dotnet run -- -n --target d:\backup try an ssh run: dotnet run -- -n --target root@sylecn01.emacsos.com:/data/backup/PC-backup/B75I3/ it works. file list works. ssh transfer works. remote logging works. ** 2019-11-12 docs - rsync https://www.samba.org/ftp/rsync/rsync.html Loading Loading @@ -50,9 +59,9 @@ dotnet run -- -n --target d:\backup http://fsprojects.github.io/FSharpLint/index.html * later :entry: ** 2019-11-14 supports expand Downloads dir in user-default.list * current :entry: ** ** 2019-11-13 build mbackup.list file from file list and exclude lists. ** 2019-11-13 extra user default list. Documents is replaced by real path. Downloads Loading Loading @@ -213,4 +222,5 @@ C:\ProgramData\mbackup\user-default.list it contains hostname. - * done :entry: ** 2019-11-13 build mbackup.list file from file list and exclude lists. * wontfix :entry: Loading
Program.fs +17 −16 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ type CLIArguments = | Remote_User of remoteUser: string | [<AltCommandLine("-i")>] Itemize_Changes | Node_Name of nodeName: string | Ssh_Key of sshKeyFilename: string with interface IArgParserTemplate with member s.Usage = Loading @@ -38,6 +39,7 @@ with | Remote_User _ -> "remote linux user to own the backup files" | Itemize_Changes _ -> "add -i option to rsync" | Node_Name _ -> "local node's name, used in remote logging" | Ssh_Key _ -> "ssh private key, used when backup to remote ssh node" type Logger() = let mutable level = Logger.DEBUG Loading Loading @@ -105,12 +107,18 @@ let EnsureWinDir (path: string) = if path.EndsWith "\\" then path else path + "\ let appDataRoamingDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) |> ToMingwPath |> EnsureDir let programDataDirWin = GetEnv "PROGRAMDATA" |> EnsureWinDir let programDataDir = ToMingwPath programDataDirWin let appDataLocalDirWin = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) |> EnsureDir let appDataLocalDirWin = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) |> EnsureWinDir let appDataLocalDir = appDataLocalDirWin |> ToMingwPath let mbackupInstallDirWin = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) |> EnsureDir |> fun s -> s + "mbackup" let mbackupInstallDir = mbackupInstallDirWin |> ToMingwPath let userHomeWin = GetEnvDefault "HOME" (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) |> EnsureWinDir let userHome = userHomeWin |> ToMingwPath //let userConfigDir = appDataRoamingDir + "mbackup/" let userConfigDirWin = programDataDirWin + "mbackup\\" let userConfigDir = programDataDir + "mbackup/" Loading Loading @@ -142,7 +150,6 @@ let expandUserFile (fn: string) = if fn.StartsWith("/") then fn else let userHome = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) |> ToMingwPath |> EnsureDir userHome + fn // generate mbackup.list file Loading @@ -159,10 +166,10 @@ let generateMbackupList (logger: Logger) = let readMbackupListFile fn = File.ReadAllLines(fn) |> dropEmptyLinesAndComments try let defaultListLines = readMbackupListFile mbackupDefaultList let defaultListLines = readMbackupListFile mbackupDefaultList |> Seq.map ToMingwPath let localListLinesMaybe = try let lines = readMbackupListFile mbackupLocalList let lines = readMbackupListFile mbackupLocalList |> Seq.map ToMingwPath (true, lines) with | :? System.IO.FileNotFoundException -> Loading Loading @@ -199,8 +206,8 @@ let main argv = let logger = Logger() logger.Info "userConfigDir=%s" userConfigDir logger.Info "runtimeDir=%s" runtimeDir logger.Info "using user config dir: %s" userConfigDirWin logger.Info "using runtime dir: %s" runtimeDirWin let rsyncCmd: string list = [] let rsyncCmd = appendWhen dryRun rsyncCmd "--dry-run" Loading @@ -224,8 +231,8 @@ let main argv = let mbackupInstallDirWinTest = "D:\\downloads\\apps\\mbackupTest\\" let mbackupInstallDirTest = mbackupInstallDirWinTest |> ToMingwPath |> EnsureDir let sshExeFile = mbackupInstallDirTest + "rsync-w64/usr/bin/ssh.exe" let sshConfigFile = userConfigDir + "ssh_config" let sshPrivateKeyFile = userConfigDir + "ssh_id_rsa" let sshConfigFile = userHome + ".ssh/config" let sshPrivateKeyFile = results.GetResult(Ssh_Key, defaultValue = userHome + ".ssh/id_rsa") |> ToMingwPath let rsyncCmd = List.append rsyncCmd [sprintf "-e \"%s -F %s -i %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\"" sshExeFile sshConfigFile sshPrivateKeyFile] let backupTarget = results.GetResult (Target, defaultValue = Environment.GetEnvironmentVariable "TARGET") Loading @@ -238,13 +245,7 @@ let main argv = let rsyncCmd = if not (isLocalTarget backupTarget) then let nodeName = match results.GetResult Node_Name with | null -> match GetEnv "NODE_NAME" with | null -> Net.Dns.GetHostName() | X -> X | X -> X let nodeName = results.GetResult(Node_Name, defaultValue = Net.Dns.GetHostName()) let remoteLogFile = sprintf "/var/log/mbackup/%s.log" nodeName let remoteUser = results.GetResult (Remote_User, defaultValue = Environment.UserName) let rsyncCmd = List.append rsyncCmd [sprintf "--remote-option=--log-file=%s" remoteLogFile] Loading
mbackup-config/mbackup-default.list +3 −3 Original line number Diff line number Diff line # dirs to backup /cygdrive/c/ProgramData/mbackup /cygdrive/c/path/to/dir /cygdrive/d/path/to/dir C:\ProgramData\mbackup C:\path\to\dir D:\path\to\dir
operational +11 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,15 @@ dotnet run -- --dry-run --itemize-changes --target d:\backup dotnet run -- -n -i --target d:\backup dotnet run -- -n --target d:\backup try an ssh run: dotnet run -- -n --target root@sylecn01.emacsos.com:/data/backup/PC-backup/B75I3/ it works. file list works. ssh transfer works. remote logging works. ** 2019-11-12 docs - rsync https://www.samba.org/ftp/rsync/rsync.html Loading Loading @@ -50,9 +59,9 @@ dotnet run -- -n --target d:\backup http://fsprojects.github.io/FSharpLint/index.html * later :entry: ** 2019-11-14 supports expand Downloads dir in user-default.list * current :entry: ** ** 2019-11-13 build mbackup.list file from file list and exclude lists. ** 2019-11-13 extra user default list. Documents is replaced by real path. Downloads Loading Loading @@ -213,4 +222,5 @@ C:\ProgramData\mbackup\user-default.list it contains hostname. - * done :entry: ** 2019-11-13 build mbackup.list file from file list and exclude lists. * wontfix :entry: