This PowerShell script, fcswitch-config-backup.ps1
, automates the backup of B-type Fibre Channel (FC) switch configurations using the Brocade Fabric OS (FOS) REST API. It provides a robust solution for Windows environments running PowerShell 7.1 or later. The script authenticates with the switch, retrieves the configuration, decodes base64-encoded data, saves both text and base64 output files, and logs out cleanly.
- Supports token-based and basic authentication.
- Retrieves switch configuration via the FOS REST API (
/rest/operations/configupload
). - Saves human-readable (
.txt
) and base64 (.b64
) configuration files. - Comprehensive logging for debugging and monitoring.
- Handles SSL verification (optional) and error conditions gracefully.
- Compatible with Brocade FOS v9.2.1a and later.
- PowerShell: Version 7.1 or later.
- Operating System: Windows (or any OS supporting PowerShell 7.1+).
- Network Access: Connectivity to the B-type FC switch over HTTPS (port 443).
- Credentials: Administrative username and password for the switch.
- Execution Policy: Set to
RemoteSigned
orBypass
(runSet-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
).
-
Clone the Repository:
git clone https://github.com/<your-username>/fcswitch-config-backup-powershell.git cd fcswitch-config-backup-powershell
-
Ensure PowerShell 7.1+: Verify your PowerShell version:
$PSVersionTable.PSVersion
If needed, install PowerShell 7.1+ from Microsoft's PowerShell GitHub.
-
Set Execution Policy (if not already set):
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Run the script from the command line, specifying the switch IP and username. The script prompts for the password securely.
.\fcswitch-config-backup.ps1 -IP <switch-ip> -Username <username> [-OutputFile <filename>] [-VerifySSL] [-Debug]
-IP
(required): The IP address of the Brocade FC switch (e.g.,192.168.1.100
).-Username
(required): The switch username (typicallyadmin
).-OutputFile
(optional): Custom base name for output files (default:fc_switch_config_<ip>_<timestamp>
).-VerifySSL
(optional): Enable SSL certificate verification (default: disabled).-Debug
(optional): Enable verbose logging for troubleshooting.
- Text File: Human-readable configuration (e.g.,
fc_switch_config_192_168_1_100_20250705_094500.txt
). - Base64 File: Raw base64 configuration for restores (e.g.,
fc_switch_config_192_168_1_100_20250705_094500.b64
). - Log File: Detailed execution log (
fcswitch_config_backup.log
).
-
Basic Backup:
.\fcswitch-config-backup.ps1 -IP 192.168.1.100 -Username admin
Prompts for password and saves config files in the current directory.
-
Custom Output File with SSL Verification:
.\fcswitch-config-backup.ps1 -IP 192.168.1.100 -Username admin -OutputFile my_config -VerifySSL
Saves
my_config.txt
andmy_config.b64
. -
Debug Mode:
.\fcswitch-config-backup.ps1 -IP 192.168.1.100 -Username admin -Debug
Logs detailed debugging info to
fcswitch_config_backup.log
. -
Scheduled Backup: Schedule daily backups using Task Scheduler:
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument "-File C:\path\to\fcswitch-config-backup.ps1 -IP 192.168.1.100 -Username admin" $trigger = New-ScheduledTaskTrigger -Daily -At "2:00AM" Register-ScheduledTask -TaskName "FCSwitchBackup" -Action $action -Trigger $trigger -Description "Daily FC switch config backup"
Note: Store the password securely (e.g., using a credential manager).
- HTTP 415 (Unsupported Media Type):
- Ensure the logout request uses
Accept: application/yang-data+json
andContent-Type: application/yang-data+json
. - Check the log (
fcswitch_config_backup.log
) forLogout exception details
.
- Ensure the logout request uses
- Authentication Errors:
- Verify the username and password.
- Check switch permissions (admin role required).
- Run
restconfig --show
on the switch to confirmhttp.enabled:1
andhttp.ssl.enabled:1
.
- Session Limits:
- The switch limits REST sessions (
http.maxrestsession:10
). To manage sessions:- Log in to the switch via SSH (FOS CLI):
ssh admin@192.168.1.100
- List active REST sessions:
mgmtapp --showsessions
- Terminate a specific session if needed:
mgmtapp --terminate <session_id>
- Log in to the switch via SSH (FOS CLI):
- The switch limits REST sessions (
- Verbose Logging:
- Use
-Debug
to capture detailed logs:.\fcswitch-config-backup.ps1 -IP 192.168.1.100 -Username admin -Debug
- Use
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature
). - Commit changes (
git commit -m "Add your feature"
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
Please include:
- Detailed descriptions of changes.
- Tests to verify functionality.
- Updates to this README if new features are added.
This project is licensed under the MIT License. See the LICENSE file for details.
This script is not affiliated with, supported by, or endorsed by Broadcom or Brocade.
- Thanks to the Brocade Fabric OS REST API Reference Manual for detailed endpoint specifications.
- For Python-based Brocade FOS REST API examples, see Jack Consoli’s excellent brocade-rest-api-examples repository.
- Special shoutout to the community for debugging insights on HTTP 415 errors.