#
# Default Bareos Director Configuration file
#
#  The only thing that MUST be changed is to add one or more
#   file or directory names in the Include directive of the
#   FileSet resource.
#
#  You might also want to change the default email address
#   from root to your address.  See the "mail" and "operator"
#   directives in the Messages resource.
#

Director {                            # define myself
  Name = 127.0.0.1-dir
  Port = 8101                # where we listen for UA connections
  QueryFile = "/tmp/git/bareos/regress/bin/query.sql"
  WorkingDirectory = "/tmp/git/bareos/regress/working"
  Maximum Concurrent Jobs = 4
  Password = "pNvX1WiXnwv2C/F7E52LGvw6rKjbbPvu2kyuPa9pVaL3"         # Console password
  Messages = Standard
}

JobDefs {
  Name = "DefaultJob"
  Type = Backup
  Level = Incremental
  Client = 127.0.0.1-fd
  FileSet = FS_TESTJOB
  Storage = File
  Messages = Standard
  Pool = Default
  Priority = 10
  Maximum Concurrent Jobs = 16
}

FileSet {
 Name = FS_TESTJOB
 Include {
   File=</tmp/git/bareos/regress/tmp/file-list
 }
}

#dir: BeforeJob: run command "/bin/echo RunBeforeJob"
#fd: ClientRunBeforeJob: ClientRunBeforeJob
#fd: ClientAfterJob: run command "/bin/echo ClientRunAfterJob"
#dir: AfterJob: run command "/bin/echo RunAfterJob"

Job {
  Name = "RUN_ALL_OK"
  JobDefs = DefaultJob
  FileSet = FS_TESTJOB
  RunBeforeJob = "/bin/echo RunBeforeJob"
  ClientRunBeforeJob = "/bin/echo ClientRunBeforeJob"
  Run After Job = "/bin/echo RunAfterJob"
  ClientRunAfterJob = "/bin/echo ClientRunAfterJob"
  RunScript {
    Command = "/bin/echo ClientRunBefore1"
    Command = "/bin/echo ClientRunBefore2"
    Command = "/bin/echo ClientRunBefore3"
    Command = "/bin/echo ClientRunBefore4"
    RunsWhen = Before
  }
}

# first, you need to unzip win32/win32_runscript.zip to c:/temp
Job {
  Name = "RUN_WIN32"
  JobDefs = DefaultJob
  FileSet = FS_TESTJOB
  RunScript {                                              # 2.4 | 2.5 | cmd /c
     Command = "c:\\temp\\test.bat"                        # ok  | ok  | ok
     Command = "c:\\temp\\test.bat arg1"                   # ok  | ok  | ok
     Command = "c:/temp/test.bat"                          # ok  | ok  | ok
     Command = "c:/temp/test.bat arg1"                     # ok  | ok  | ok
     Command = "c:/temp/test space.bat"                    # ok  | ok  | ok
     Command = "c:/temp/test2 space.bat"                   # ok  | ok  | ok
     Command = "\"c:/temp/test space.bat\" arg1"           # ok  | ok  | ok
     Command = "\"c:/temp/dir space/test.bat\" arg1"       # ok  | ok  | ok
     Command = "c:/temp/érïc/test.bat"                     # ERR | ok  | ok
     Command = "c:/temp/érïc/test space.bat"               # ERR | ok  | ok
     Command = "c:/temp/testé.bat"                         # ERR | ok  | ok
     Command = "c:/temp/érïc/testé.bat"                    # ERR | ok  | ok
     Command = "\"c:/temp/dir space/érïc/test.bat\""       # ERR | ERR | ok
     Command = "\"c:/temp/dir space/érïc/test space.bat\"" # ERR | ERR | ok
     Command = "c:/temp/test space.bat arg1"               # ERR | ERR | ERR
     Command = "c:/temp/test2 space.bat arg1"              # ERR | ERR | ERR
     Command = "c:/temp/dir space/érïc/test.bat"           # ERR | ERR | ERR
     Command = "c:/temp/dir space/test.bat"                # ERR | ERR | ERR
     Command = "'c:/temp/dir space/test.bat'"              # ERR | ERR | ERR
     Command = "\"c:/temp/éric space/test.bat\""           # ERR | ERR | ERR
     Command = "c:/temp/éric space/test.bat"               # ERR | ERR | ERR
     RunsWhen = Before
     FailJobOnError = no
  }
}

Job {
  Name = "RUN_SUBST"
  JobDefs = DefaultJob
  FileSet = FS_TESTJOB
  RunBeforeJob = "/bin/echo client_name=%c (127.0.0.1-fd) dir_name=%d (127.0.0.1-dir) jobid=%i job=%n type=%t"
  ClientRunBeforeJob = "/bin/echo client_name=%c (127.0.0.1-fd) dir_name=%d (127.0.0.1-dir) jobid=%i job=%n type=%t"
  ClientRunAfterJob = "/bin/echo client_name=%c (127.0.0.1-fd) dir_name=%d (127.0.0.1-dir) jobid=%i job=%n type=%t"
  Run After Job = "/bin/echo client_name=%c (127.0.0.1-fd) dir_name=%d (127.0.0.1-dir) jobid=%i job=%n type=%t vol=%v status=%e"
}


#After job are after before job
Job {
  Name = "RUN_DIR_FAILED_BUG"
  FileSet = FS_TESTJOB
  JobDefs = DefaultJob
  Run After Failed Job = "/bin/echo RunAfterFailedJob"
  RunBeforeJob = "/bin/false"
}

#127.0.0.1-dir: BeforeJob: run command "/bin/false"
#127.0.0.1-dir: BeforeJob: RunAfterFailedJob
Job {
  Name = "RUN_DIR_FAILED"
  FileSet = FS_TESTJOB
  JobDefs = DefaultJob
  RunBeforeJob = "/bin/false RUN_DIR_FAILED"
  Run After Failed Job = "/bin/echo RunAfterFailedJob"
}

#127.0.0.1-fd: ClientBeforeJob: run command "/bin/false RUN_FD_FAILED1"
#127.0.0.1-fd: ClientBeforeJob: run command "/bin/false RUN_FD_FAILED2"
#127.0.0.1-fd: ClientBeforeJob: run command "/bin/false RUN_FD_FAILED3"
#127.0.0.1-dir: AfterJob: run command "/bin/echo RunAfterFailedJob"
Job {
  Name = "RUN_FD_FAILED"
  FileSet = FS_TESTJOB
  JobDefs = DefaultJob
  RunScript {
    Command = "/bin/false RUN_FD_FAILED1"
    Command = "/bin/false RUN_FD_FAILED2"
    failjobonerror = no
    RunsWhen = Before
  }
  RunScript {
    Command = "/bin/false RUN_FD_FAILED3"
    Command = "/bin/false RUN_FD_FAILED4"
    failjobonerror = yes
    RunsWhen = Before
  }

  Run After Failed Job = "/bin/echo RunAfterFailedJob"
  RunScript {
    Command = "/bin/echo touching /tmp/git/bareos/regress/tmp/RUN_FD_FAILED"
    RunsWhen = after
    RunsOnFailure = yes
  }
  RunScript {
    Command = "/bin/touch /tmp/git/bareos/regress/tmp/RUN_FD_FAILED"
    RunsWhen = after
    RunsOnFailure = yes
  }
}

#127.0.0.1-fd: ClientBeforeJob: run command "/bin/false RUN_FD_FAILED1"
#we don't execute FAILED2
#127.0.0.1-dir: AfterJob: run command "/bin/echo RunAfterFailedJob"
Job {
  Name = "RUN_FD_FAILED2"
  FileSet = FS_TESTJOB
  JobDefs = DefaultJob
  RunScript {
    Command = "/bin/false RUN_FD_FAILED1"
    failjobonerror = yes
    RunsWhen = Before
  }
  RunScript {
    Command = "/bin/false RUN_FD_FAILED2"
    failjobonerror = yes
    RunsWhen = Before
  }
  RunScript {
    Command = "/bin/false RUN_FD_FAILED3"
    failjobonerror = yes
    RunsOnFailure = yes
    RunsWhen = Before
  }

  Run After Failed Job = "/bin/echo RunAfterFailedJob"
}

#127.0.0.1-fd: ClientBeforeJob: run command "/bin/false RUN_FD_WARNING"
#Backup OK -- with warnings
Job {
  Name = "RUN_FD_WARNING"
  FileSet = FS_TESTJOB
  JobDefs = DefaultJob
  RunScript {
    Command = "/bin/false RUN_FD_WARNING"
    failjobonerror = no
    RunsWhen = Before
  }
  Run After Failed Job = "/bin/echo RunAfterFailedJob"
}

Job {
  Name = "RUN_CONSOLE_CMD"
  FileSet = FS_TESTJOB
  JobDefs = DefaultJob
  RunScript {
    Console = "purge volume=TestVolume001 yes"
    Console = "st dir"
    RunsWhen = Before
    failjobonerror = no
    runsonclient = no
  }
}

Job {
  Name = "Restore"
  Type = Restore
  Client = 127.0.0.1-fd
  FileSet = FS_TESTJOB
  Storage = File
  Messages = Standard
  Pool = Default

  RunScript  {
   RunsWhen = Before
   RunsOnClient = Yes
   Command = "echo ClientBeforeRestore"
  }

  RunScript  {
   RunsOnFailure = No
   RunsWhen = After
   RunsOnClient = Yes
   Command = "echo ClientAfterRestore"
  }

  RunScript  {
   RunsWhen = Before
   RunsOnClient = No
   Command = "echo DirBeforeRestore"
  }

  RunScript  {
   RunsOnFailure = No
   RunsWhen = After
   RunsOnClient = Yes
   Command = "echo DirAfterRestore"
  }
}

# Client (File Services) to backup
Client {
  Name = 127.0.0.1-fd
  Address = 127.0.0.1
  Port = 8102
  Catalog = MyCatalog
  Password = "xevrjURYoCHhn26RaJoWbeWXEY/a3VqGKp/37tgWiuHc"          # password for FileDaemon
  File Retention = 30d                # 30 days
  Job Retention = 180d                # six months
  AutoPrune = yes                     # Prune expired Jobs/Files
  Maximum Concurrent Jobs = 4
}

# Definiton of file storage device
Storage {
  Name = File
  Address = 127.0.0.1                # N.B. Use a fully qualified name here
  Port = 8103
  Password = "ccV3lVTsQRsdIUGyab0N4sMDavui2hOBkmpBU0aQKOr9"
  Device = FileStorage
  Media Type = File
  Maximum Concurrent Jobs = 4
}

# Generic catalog service
Catalog {
  Name = MyCatalog

  dbname = regress
  user = regress
  password = ""
}


Messages {
  Name = Standard
  console = all, !skipped, !saved, !audit
  catalog = all, !skipped, !audit
}

# Default pool definition
Pool {
  Name = Default
  Pool Type = Backup
  Recycle = yes                       # Bareos can automatically recycle Volumes
  AutoPrune = yes                     # Prune expired volumes
  Volume Retention = 365d             # one year
}
