Automatic backup and precautions using date variables
Description
Instructions on how to indicate the date in the file name in relation to FortiGate's automatic backup.
Scope
FortiGate 7.0, 7.2, 7.4, 7.6, 8.0.
Solution
Step 1: Configure the automation trigger. For more information, refer to Automation stitches.
To trigger the automation stitch daily at 2 AM local time, configure the following:
Â
config system automation-trigger
edit "backup_test"
set trigger-type scheduled
set trigger-hour 02
set trigger-minute 00
next
endÂ
Step 2: Configure the automation action.
To perform the backup using a CLI script, configure the following:
Â
config system automation-action
  edit "date_backup_test"
    set action-type cli-script
    set script "execute backup config sftp %%date%%_FGT_backup.conf 10.0.3.225 my-ftp-user qwe123"
    set accprofile "super_admin"
  next
endÂ
The backup command can be modified to use a different file transfer method. For FTP, the port number and username are optional, depending on the FTP server configuration:
Â
execute backup config ftp <backup_filename> <ftp_server>[<:ftp_port>] [<user_name>] [<password>] [<backup_password>]Â
TFTP:
execute backup config tftp <backup_filename> <tftp_servers> [<backup_password>]Â
SFTP:
execute backup config sftp <backup_filename> <sftp_server>[<:sftp_port>] <user> <password> [<backup_password>]Â
The optional <backup_password> parameter can be used to encrypt the configuration backup file. This password is separate from the credentials used to access the FTP or SFTP server. When configuring an automated backup, specify the backup password as the final parameter of the "execute backup config" command to encrypt the backup file. The password is required when restoring the encrypted configuration backup.
Â
If VDOM is enabled, add a "config global" line to the script:
Â
config system automation-action
  edit "date_backup_test"
    set action-type cli-script
    set script "config global
      execute backup config sftp %%date%%.conf 10.0.3.225 my-sftp-user qwe123
      end"
    set accprofile "super_admin"
  next
endÂ
Although the command is run in the global VDOM, the file transfer itself will be attempted using the management VDOM's interfaces and routing. For more information, refer to the VDOM overview section of the FortiOS 8.0.0 Administration Guide.
Â
Step 3:Â Configure the automation stitch.
Combine the settings from Steps 1 and 2 to create the automation configuration.
Â
config system automation-stitch
  edit "backup_test"
    set status enable
    set trigger "backup_test"
    config actions
      edit 1
        set action "date_backup_test"
        set required enable
      next
    end
  next
endÂ
Step 4: Verify the result.
If the file name specified in Step 2 includes '%%date%%', the variable is replaced with the current date in 'YYYY-MM-DD' format when the automation stitch runs.
Â
For example, the following command variant produces outputs like 2023-09-19.conf and 2023-09-20.conf:
Â
set script "execute backup config sftp %%date%%.conf 10.0.3.225 my-sftp-user qwe123"Â
It is also possible to have static text around these variables to produce more descriptive file names. For example, the following command variant would produce files with names like FGT_2023-09-19_backup.conf and FGT_2023-09-20_backup.conf
Â
set script "execute backup config ftp FGT_%%date%%_backup.conf 10.0.3.225 my-ftp-user qwe123"Â
Caution:
Verify the result after configuring the automation stitch.
'%%date%%', '%%time%%', and other automation variables are a feature of the automation stitch, not the CLI command itself. They are not supported when running the 'execute backup' command manually from the CLI.
If the command is run manually from CLI, '%%date%%' will appear in the filename on the remote server. Alternatively, the backup job may fail if the remote server does not allow the '%' character in filenames.
Â

Â
If the backup was triggered by the automation action script, the date will be generated correctly and appear in the filename on the remote server.
Â

Â
Note on configuration type:
FortiGate supports two configuration backup methods:
execute backup config: Saves only the active configuration (non-default settings).
execute backup full-config: Saves the full configuration, including all default values.
When scheduling automated backups, either command can be used in the automation script.
For more details on the difference between the two commands, see the article Technical Tip: Differences between FortiGate CLI commands 'execute backup config' and 'execute backup full-config'.
Important Notice:
Starting from FortiOS 8.0.1-build 0185, the auto-script engine only allows information-gathering commands (get, diagnose); "execute" commands are not permitted in auto-script. Thus, backup using the auto-script feature will fail with the message 'unknown action or command is unavailable in auto-script'.
Â
Related documents:
