F5 backup
Jump to navigation
Jump to search
https://github.com/sebastien6/f5-backup
https://support.f5.com/csp/article/K13132
https://my.f5.com/manage/s/article/K13132
tmsh save sys ucs $(echo $HOSTNAME | cut -d'.' -f1)-$(date +%H%M-%m%d%y)
restore
tmsh load /sys ucs <path/to/UCS> no-license
simple script
file=$HOSTNAME.$(date +%Y-%m-%dT%H-%M-%S) tmsh save /sys ucs $file passphrase changeme tmsh list /sys ucs sftp foo@example.com <<< "put /var/local/ucs/$file" tmsh delete sys ucs $file
no private keys
tmsh save /sys ucs $file passphrase changeme no-private-key
or util.bash.exec_cmd
API Timeout
Increase timeout values:
tmsh modify sys db icrd.timeout value 180 tmsh modify sys db restjavad.timeout value 180 tmsh modify sys db restnoded.timeout value 180
tmsh save sys config tmsh restart sys service restjavad tmsh restart sys service restnoded
Python function
def sftp_backup(f5_host, ts): file=f"{f5_host}.{ts}.ucs" # cmd_args = f"-c \"set -eu; tmsh save /sys ucs {file} passphrase {UCS_BKP_PASS}; echo done\"" # r = mgmt.tm.util.bash.exec_cmd('run', utilCmdArgs=cmd_args) # pp.pprint(cmd_args) # print("===========") # pp.pprint(r.commandResult) print(f"Backing up UCS on {f5_host}") mgmt.tm.sys.ucs.exec_cmd('save', name=file) print(f"Done Backing up UCS on {f5_host}") print(f"Uploading UCS on {f5_host} and uploading to sftp service. Takes 2-5 minutes usually.") cmd_args = f"-c \"set -eu; ssh-keygen -R {SFTP_HOST} 2>/dev/null; ssh-keyscan -t ecdsa -H {SFTP_HOST} >> ~/.ssh/known_hosts 2>/dev/null; echo put /var/local/ucs/{file} | sftp {SFTP_USER}@{SFTP_HOST}; tmsh delete sys ucs {file}; echo done\"" r = mgmt.tm.util.bash.exec_cmd('run', utilCmdArgs=cmd_args) pp.pprint(cmd_args) print("===========") pp.pprint(r.commandResult)
More
cmd_args = "-c \"set -eu; file=$HOSTNAME.$(date +%Y-%m-%dT%H-%M-%S).ucs; sftphost=10.x.x.x; tmsh save /sys ucs $file passphrase changeme; sleep 20; ssh-keygen -R $sftphost 2>/dev/null; ssh-keyscan -t ecdsa -H $sftphost >> ~/.ssh/known_hosts 2>/dev/null; echo put /var/local/ucs/$file | sftp myuser@$sftphost; tmsh delete sys ucs $file; echo done\""