* Added `scriptEnvFile` to command object that allows one to specify an environment file (or any file really) when a `scriptFile` is run. Inspired by the practice of keeping environment variables and scripts or commands seperate.
* Basis for listing commands
### Changed
* BREAKING: Notifications object now takes the form of service.id, where service can be "mail" or "matrix" and id is a unique id for the service.
* BREAKING: Since the change to the notifications object, cmd-lists' inner map key 'notifications' must be of the form service.id. id must be defined for that service. See notifications docs for aviliable services.
* Config parser is now the simpler Koanf - Keys are now case-sensitive
Short:"Lists commands, lists, or hosts defined in config file.",
Long:"Backup lists commands or groups defined in config file.\nUse the --lists or -l flag to list the specified lists. If not flag is not given, all lists will be executed.",
Run:List,
}
)
varlistsToList[]string
funcinit(){
listCmd.Flags().StringSliceVarP(&listsToList,"lists","l",nil,"Accepts comma-separated names of command lists to list.")
@ -16,8 +16,8 @@ The top-level object key can be anything you want but not the same as another.
- test
- test2
notifications:
- prod-email
- matrix
- mail.prod-email
- matrix.sysadmin
cron: "0 * ** * *"
```
@ -25,9 +25,9 @@ The top-level object key can be anything you want but not the same as another.
| --- | --- | --- | --- |
| `order` | Defines the sequence of commands to execute | `[]string` | yes |
| `getOutput` | Command(s) output is in the notification(s) | `bool` | no |
| `notifications` | The notification IDs to use on success and failure | `[]string` | no |
| `notifications` | The notification service(s) and ID(s) to use on success and failure. Must be *`service.id`*. See the [notifications documentation page](/config/notifications/) for more | `[]string` | no |
| `name` | Optional name of the list | `string` | no |
| `cron` | Time at which to schedule the list. | `string` | no |
| `cron` | Time at which to schedule the list. Only has affect when cron subcommand is run. | `string` | no |
### Order
@ -43,7 +43,7 @@ order:
Get command output when a notification is sent.
Is not required. Can be `true` or `false`.
Is not required. Can be `true` or `false`. Default is `false`.
### Notifications
@ -57,29 +57,30 @@ Name is optional for logging. If name is not defined, name will be the object's
Backy also has a cron mode, so one can run `backy cron` and start a process that schedules jobs to run at times defined in the configuration file.
Adding `cron: 0 0 1 * * *`to a `cmd-configs` object will schedule the list at 1 in the morning. See [https://crontab.guru/](https://crontab.guru/) for reference.
Adding `cron: 0 0 1 * * *`to a `cmd-lists` object will schedule the list at 1 in the morning. See [https://crontab.guru/](https://crontab.guru/) for reference.
{{% notice tip %}}
Note: Backy uses the second field of cron, so add anything except * to the beginning of a regular cron expression.
{{% /notice %}}
```yaml
cmd-configs:
cmds-to-run: # this can be any name you want
cmd-lists:
docker-container-backup: # this can be any name you want
// SetupNotify sets up notify instances for each command list.
func(opts*ConfigOpts)SetupNotify(){
func(backyConfig*ConfigFile)SetupNotify(){
// check if we have individual commands instead of lists to execute
iflen(opts.executeCmds)!=0{
return
}
for_,cmdConfig:=rangebackyConfig.CmdConfigLists{
forconfName,cmdConfig:=rangeopts.CmdConfigLists{
varservices[]notify.Notifier
fornotifyID:=rangebackyConfig.Notifications{
ifcontains(cmdConfig.Notifications,notifyID){
for_,id:=rangecmdConfig.Notifications{
if!strings.Contains(id,"."){
opts.Logger.Info().Str("id",id).Str("list",cmdConfig.Name).Msg("key does not contain a \".\" Make sure to follow the docs: https://backy.cybershell.xyz/config/notifications/")
logging.ExitWithMSG(fmt.Sprintf("notification id %s in cmd list %s does not contain a \".\" \nMake sure to follow the docs: https://backy.cybershell.xyz/config/notifications/",id,cmdConfig.Name),1,&opts.Logger)
logging.ExitWithMSG(Sprintf("Config key %s is not defined in %s. Please make sure this value is set and has the appropriate keys set.",key,config.ConfigFileUsed()),1,nil)
logging.ExitWithMSG(Sprintf("Config key %s is not defined in %s. Please make sure this value is set and has the appropriate keys set.",key, file),1,nil)