F5 iApp Automated Backup
Problem this snippet solves:
This is now available on GitHub!
Please look on GitHub for the latest version, and submit any bugs or questions as an "Issue" on GitHub:
(Note: DevCentral admin update - Daniel's project appears abandoned so it's been forked and updated to the link below. @damnski on github added some SFTP code that has been merged in as well.)
https://github.com/f5devcentral/f5-automated-backup-iapp
Intro
Building on the significant work of Thomas Schockaert (and several other DevCentralites) I enhanced many aspects I needed for my own purposes, updated many things I noticed requested on the forums, and added additional documentation and clarification. As you may see in several of my comments on the original posts, I iterated through several 2.2.x versions and am now releasing v3.0.0. Below is the breakdown!
Also, I have done quite a bit of testing (mostly on v13.1.0.1 lately) and I doubt I've caught everything, especially with all of the changes. Please post any questions or issues in the comments.
Cheers!
Daniel Tavernier (tabernarious)
Related posts:
- Git Repository for f5-automated-backup-iapp (https://github.com/tabernarious/f5-automated-backup-iapp)
- https://community.f5.com/t5/technical-articles/f5-automated-backups-the-right-way/ta-p/288454
- https://community.f5.com/t5/crowdsrc/complete-f5-automated-backup-solution/ta-p/288701
- https://community.f5.com/t5/crowdsrc/complete-f5-automated-backup-solution-2/ta-p/274252
- https://community.f5.com/t5/technical-forum/automated-backup-solution/m-p/24551
- https://community.f5.com/t5/crowdsrc/tkb-p/CrowdSRC
v3.2.1 (20201210)
- Merged v3.1.11 and v3.2.0 for explicit SFTP support (separate from SCP).
- Tweaked the SCP and SFTP upload directory handling; detailed instructions are in the iApp.
- Tested on 13.1.3.4 and 14.1.3
v3.1.11 (20201210)
- Better handling of UCS passphrases, and notes about characters to avoid.
- I successfully tested this exact passphrase in the 13.1.3.4 CLI (surrounded with single quote) and GUI (as-is): `~!@#$%^*()aB1-_=+[{]}:./?
- I successfully tested this exact passphrase in 14.1.3 (square-braces and curly-braces would not work): `~!@#$%^*()aB1-_=+:./?
- Though there may be situations these could work, avoid these characters (separated by spaces): " ' & | ; < > \ [ ] { } ,
- Moved changelog and notes from the template to CHANGELOG.md and README.md.
- Replaced all tabs (\t) with four spaces.
v3.1.10 (20201209)
- Added SMB Version and SMB Security options to support v14+ and newer versions of Microsoft Windows and Windows Server.
- Tested SMB/CIFS on 13.1.3.4 and 14.1.3 against Windows Server 2019 using "2.0" and "ntlmsspi"
v3.1.0:
- Removed "app-service none" from iCall objects. The iCall objects are now created as part of the Application Service (iApp) and are properly cleaned up if the iApp is redeployed or deleted.
- Reasonably tested on 11.5.4 HF2 (SMB worked fine using "mount -t cifs") and altered requires-bigip-version-min to match.
- Fixing error regarding "script did not successfully complete: (can't read "::destination_parameters__protocol_enable": no such variable" by encompassing most of the "implementation" in a block that first checks $::backup_schedule__frequency_select for "Disable".
- Added default value to "filename format".
- Changed UCS default value for $backup_file_name_extension to ".ucs" and added $fname_noext.
- Removed old SFTP sections and references (now handled through SCP/SFTP).
- Adjusted logging: added "sleep 1" to ensure proper logging; added $backup_directory to log message.
- Adjusted some help messages.
New v3.0.0 features:
- Supports multiple instances! (Deploy multiple copies of the iApp to save backups to different places or perhaps to keep daily backups locally and send weekly backups to a network drive.)
- Fully ConfigSync compatible! (Encrypted values now in $script instead of local file.)
- Long passwords supported! (Using "-A" with openssl which reads/writes base64 encoded strings as a single line.)
- Added $script error checking for all remote backup types! (Using 'catch' to prevent tcl errors when $script aborts.)
- Backup files are cleaned up after any $script errors due to new error checking.
- Added logging! (Run logs sent to '/var/log/ltm' via logger command which is compatible with BIG-IP Remote Logging configuration (syslog). Run logs AND errors sent to '/var/tmp/scriptd.out'. Errors may include plain-text passwords which should not be in /var/log/ltm or syslog.)
- Added custom cipher option for SCP! (In case BIG-IP and the destination server are not cipher-compatible out of the box.)
- Added StrictHostKeyChecking=no option. (This is insecure and should only be used for testing--lots of warnings.)
- Combined SCP and SFTP because they are both using SCP to perform the remote copy. (Easier to maintain!)
Original v1.x.x and v2.x.x features kept (copied from an original post):
- It allows you to choose between both UCS or SCF as backup-types. (whilst providing ample warnings about SCF not being a very good restore-option due to the incompleteness in some cases)
- It allows you to provide a passphrase for the UCS archives (the standard GUI also does this, so the iApp should too)
- It allows you to not include the private keys (same thing: standard GUI does it, so the iApp does it too)
- It allows you to set a Backup Schedule for every X minutes/hours/days/weeks/months or a custom selection of days in the week
- It allows you to set the exact time, minute of the hour, day of the week or day of the month when the backup should be performed (depending on the usefulness with regards to the schedule type)
- It allows you to transfer the backup files to external devices using 4 different protocols, next to providing local storage on the device itself
- SCP (username/private key without password)
- SFTP (username/private key without password)
- FTP (username/password)
- SMB (now using TMOS v12.x.x compatible 'mount -t cifs', with username/password)
- Local Storage (/var/local/ucs or /var/local/scf)
- It stores all passwords and private keys in a secure fashion: encrypted by the master key of the unit (f5mku), rendering it safe to store the backups, including the credentials off-box
- It has a configurable automatic pruning function for the Local Storage option, so the disk doesn't fill up (i.e. keep last X backup files)
- It allows you to configure the filename using the date/time wildcards from the tcl [clock] command, as well as providing a variable to include the hostname
- It requires only the WebGUI to establish the configuration you desire
- It allows you to disable the processes for automated backup, without you having to remove the Application Service or losing any previously entered settings
- For the external shellscripts it automatically generates, the credentials are stored in encrypted form (using the master key)
- It allows you to no longer be required to make modifications on the linux command line to get your automated backups running after an RMA or restore operation
- It cleans up after itself, which means there are no extraneous shellscripts or status files lingering around after the scripts execute
How to use this snippet:
- Find and download the latest iApp template on GitHub (e.g "f5.automated_backup.v3.2.1.tmpl.tcl").
- Import the text file as an iApp Template in the BIG-IP GUI.
- Create an Application Service using the imported Template.
- Answer the questions (paying close attention to the help sections).
- Check /var/tmp/scriptd.out for general logs and errors.
Tested this on version:
16.0
- Travis_Kamish_2Nimbostratus
Has anyone run into cipher issues. My SCP server was recently hardened and now only except the following cipher "aes128-ctr,aes192-ctr,aes256-ctr" I am getting the following error. I also tried to change the cipher in the template but that gets same results. I am running auto_backup v3.1.8 and I am
generated this Tcl error: script did not successfully complete: (no matching cipher found: client aes128-cbc,aes256-cbc server aes128-ctr,aes192-ctr,aes256-ctr lost connection while executing
- Daniel_TavernieCirrostratusv3.1.8 RELEASED
These are the fixes/enhancements (I released v3.1.5 and v3.1.6 recently, so they are included):
- Updated KNOWN ISSUES section (below)
- Fixed SCF passphase issue (v11 "tmsh save sys config file NAME" works and applies no passphase ("no-passphase" flag does not exist); v12+ requires use of "no-passphrase" or "passphrase PHRASE"). (github Issue 18)
- Reordered filename_format list; default remains ${host}_%Y%m%d_%H%M%S
- Tested on 11.6.3.3, 12.1.3.7, and 13.1.1.2
- Fixed lots of issues with SCF files for SFTP/SCP, FTP, and SMB/CIFS (mainly, tar files were not being copied and were not being cleaned up locally). (github Issue 18)
- Added logging clarification that when using SCF archives a .tar file is also generated and saved/uploaded.
- Added debug logging for the SMB/CIFS script.
- Now including on github an expanded form of the upload scripts for better understanding (see "; etc.).
- Now supporting many special characters for passwords (without manually escaping with backslashes). (github Issue 3 and 16)
- SMB/CIFS does NOT support comma, single-quote, and double-quote. I successfully tested this exact password to Windows Server 2012: `~!@$%^&*()aB1-_=+[{]}|;:<.>/?
- FTP should support all characters (based on limited testing). I successfully tested this exact password to a Linux FTP server: `~!@$%^&*()aB1-_=+[{]}|;:,"<.>'/?
- Scripts for SMB/CIFS and FTP will again be deleted after each backup. (This was in place as of v3.1.6 but was turned off for debugging in v3.1.7 and was not put back.)
- Fixed comment in SMB/CIFS script which was breaking everything due hash escape and a variable reference--I must not have actually tested after I added the comment :(
- Daniel_TavernieCirrostratus
@Markie Parkie, I cannot replicate your issue, though I ran into something similar when the destination directory had the wrong permissions (username configured in iApp didn't have write permissions to the directory). Also ensure that you're pasting the OpenSSH b64 private key in this format (with newlines), though I know you've done this successfully elsewhere.
-----BEGIN RSA PRIVATE KEY----- MIIEoAIBAAKCAQEAvnvuC/FWty8k6vrccyGvNP5uabqtT6CJNpKsfgnN0aHzPQ8T xiLI007Bad6+2yW38zvUmXe2u49mFA3KGsOn02NIgehCdCQCJQEEuTW+T9W022Z1 dmAqfeFtz9H7tjq9JSoRfJXxl4lMOjB6QD0DhjE9YVpm8wSB8U4Fr560iKNLRBf6 v1UzqcxT2rqnsIlxEXVBCfC5waiNIMVO+Ipfj9ycNDLgrBpCymR6clc9IZmuJPpt ... -----END RSA PRIVATE KEY-----
Please let me know if you figure anything out!
Does the username or path have any special characters?
- Markie_Parkie_1Nimbostratus
iApp DEVICE_BACKUP: xxxxxxx.xxxxxxx.xxxxxxx_20181112_020000.ucs REMOTE COPY (SCP) STARTING
Permission denied, please try again.
Received disconnect from xx.xx.xx.xx: 2: Too many authentication failures
lost connection
iApp DEVICE_BACKUP: xxxxxxx.xxxxxxx.xxxxxxx_20181112_020000.ucs REMOTE COPY (SCP) FAILED (check for errors above)
iApp DEVICE_BACKUP: FINISHED
- Daniel_TavernieCirrostratus
@Markie Parkie, Could you paste the error from scriptd.out?
- Markie_Parkie_1Nimbostratus
Hi Tabernarious,
I have ssh to the destination server to add the fingerprint but still have the same issue. The log just says about too many Auth attempts and falls pass to password Auth.
Thanks..
- Daniel_TavernieCirrostratus
@Markie Parkie, You should be able to just have the SSH key in the iApp, BUT by default this will fail unless the destination server's SSH fingerprint has been added to '/root/.ssh/known_hosts' (or you set "StrictHostKeyChecking" to "No" in the iApp (not recommended). Have you looked at the iApp logs (/var/tmp/scriptd.out)? If you log into the BIG-IP as root and SSH to the destination server are you prompted about 'Host verification' or similar?
- Markie_Parkie_1Nimbostratus
Hi all,
Quick question on the iApp and the passwordless scp copy to remote storage.
I have the solution working fine on the first pair of BIGIPs where the keys are already stored on the device, bit doing a fresh pair now that do not have the private key in the default file but pasted into the iApp the device fails to upload to the scp destination, so it looks like I will have to copy the private key to each device to get this working.. Is this how it's meant to work, as I thought pasting it into the iApp config would do away with this part?
Currently using latest version of the template off GitHub.
Thanks..
- Daniel_TavernieCirrostratus
@efouli, I don't believe I've seen that "exec" error before. What version of this iApp are you running, and what version of TMOS are you running? And what method are you using for saving backups (local, SFTP, SMB, or FTP)?
- Daniel_TavernieCirrostratus
@Suresh and @Anthony, This filename extension issue for FTP should have been fixed in v3.1.1 (see changelog) which is carried forward to the latest version (currently v3.1.4). What version(s) of the template are you running?