- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Automation -> CLI Script: Use date as Part of filename
Hello
we use automation/cli script to backup the configuration.
How can i use the date in the filename?
Is there a parameter like %%date%%?
So that a backup would look like:
execute backup full-config ftp /Folder/backup_%%date%%.cfg user pwd
thanks for any input.
Regards
Mario
- Labels:
-
FortiGate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Mario,
if you followed my advise from your yesterday's question and used Automation Stitch to run the backup script, you can use variables %%log.date%% and %%log.time%% . The most appropriate triggers would likely be configuration change or schedule.
Action example:
config system automation-action
edit "sftp_backup"
set action-type cli-script
set script "config global
exec backup config sftp /<path>/backup_%%log.date%%_%%log.time%%.cfg <server_IP> <username> <password>"
set accprofile "super_admin"
next
end
I would highly suggest you to use the GUI wizard for automation stitches if you are not yet familiar with the CLI.
HTH,
Boris
Boris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I'm not sure if this is a bug but I've created two automation tasks. One for capturing the FGT config every night at 12:15a and one that captures changes made during the day and saving them to an FTP server. Nothing fancy.
Run this script on config changes (works as expected):
execute backup config ftp /HOSTNAME/"changes_backup_%%date%%.conf" <IP ADDRESS> <user> <password>
Run this script on a schedule (names the file with the %%date%%):
execute backup config ftp /HOSTNAME/"sched_backup_%%date%%.conf" <IP ADDRESS> <user> <password>
I've copied and pasted these commands numerous times and even tried on two different FGTs. Both are running 6.4.8 b1914. I've looked and cannot find a bug for this issue.
I did even take the %%log.date%% hoping that would work and I get the exact same results in both commands.
TIA
Created on ‎04-29-2022 12:50 AM Edited on ‎04-29-2022 01:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please upgrade to FortiOS 7.0.1 or newer to fix bug 719029 .
Alternatively raise support ticket for FortiOS 6.4.
Boris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
anyhow this date variable not working .... i tried on 7.0.2, 6.4.8 & 6.2.2, on output file it is giving the file name i.e. changes_backup_%%date%%.conf
if we will execute below scrpit
execute backup config ftp /HOSTNAME/"changes_backup_%%date%%.conf" <IP ADDRESS> <user> <password>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How are you testing the backup? If you are testing the command by directly running the below command on CLI, it won't work. This command will create a filename "backup_%%date%%.conf" on the FTP server.
execute backup config ftp backup_%%date%%.conf <server IP> <username> <password>
Please create a automation stitch and include this command as part of the action/cli-script and then you will see the file name "backup_YYYY-MM-DD.conf" format.
If your FTP server is on linux, you can also use %%time%%, time won't work on windows based FTP servers as the windows system won't allow to create filenames with ":".
Creating Automation stitch for backup: https://community.fortinet.com/t5/FortiGate/Technical-Tip-Adding-date-and-time-in-file-name-for-sche...
Once you create the stitch, you may use "test automation stitch" to test the same immediately.
Suraj
- Have you found a solution? Then give your helper a "Kudos" and mark the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
does anyone have the solution guys? or this bug will remain, since 6.4.8 firmware is not very very old but if this is the bug then i don't know when this will be fixed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6.4 reached End of Engineering Support Date (EOES) on 3/31/2023, you may plan for an upgrade to latest versions in 7.0.x or 7.2.x .
Suraj
- Have you found a solution? Then give your helper a "Kudos" and mark the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#!/bin/bash
# Get the current date in the desired format date=$(date +"%Y-%m-%d")
# Generate the filename with the date filename="/Folder/backup_${date}.cfg"
# Execute the backup command with the generated filename execute backup full-config ftp "${filename}" user pwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The script retrieves the current date using the date command and formats it as "YYYY-MM-DD". It then generates the filename by concatenating the static part ("/Folder/backup_") with the formatted date and the ".cfg" extension. Finally, it executes the backup command with the dynamically generated filename.
