---
# System prepended metadata

title: f5 自動備份 成功or失敗通知
tags: [linux shell script, 備份, f5]

---

[name=LEON.LIN]
###### tags: `linux shell script` `f5` `備份`
# f5 自動備份 成功or失敗通知

setp1:
``` bash=
server01:# ssh-keygen -t rsa
```
setp2:
``` bash=
server01:# ssh bigip1 'cat .ssh/id_rsa.pub' >> ~/.ssh/authorized_keys
or
server01: ssh-copy-id USER@HOST
```
setp3:
``` bash=
#!/bin/sh
TIMESTAMP=`date +%Y%m%d`
REMOTE_PATH="/var/tmp"
#LOCAL_PATH="/MYBACKUPS/BACKUPS_BIGIP"
LOCAL_PATH="/data/F5_conf/"
REMOTE_BIGIP=10.10.18.252
BACKUP_FILENAME=${REMOTE_BIGIP}_$TIMESTAMP.ucs


ssh $REMOTE_BIGIP tmsh save /sys ucs $REMOTE_PATH/$BACKUP_FILENAME > /dev/null

scp $REMOTE_BIGIP:$REMOTE_PATH/$BACKUP_FILENAME $LOCAL_PATH/

ssh $REMOTE_BIGIP rm $REMOTE_PATH/$BACKUP_FILENAME



MSG_BODY="This notification has been generated by the script script... located in ... "
if [ -f $LOCAL_PATH/$BACKUP_FILENAME ]
then
        MSG_SUBJECT="Backup $REMOTE_BIGIP OK ($BACKUP_FILENAME)"
        tar -zvcf "$BACKUP_FILENAME.tar" "$BACKUP_FILENAME"
        rm -rf "$BACKUP_FILENAME"    
else
        MSG_SUBJECT="Backup $REMOTE_BIGIP FAIL!!"
fi

find /data/F5_conf -mtime +90 -name "*.ucs.tar" -exec rm -rf {} \;

##echo "$MSG_BODY" | mail -aFrom:Sender\<sender@domain.com\> recipient@domain.com -s "$MSG_SUBJECT"

curl -s -X POST https://api.telegram.org/bot826950629:AAGNfDPnoXLcGfZfY-S_465ukQSjraEMuwA/sendMessage -d chat_id=-1001238056322 -d text="$REMOTE_BIGIP"_F5"$MSG_SUBJECT" &>/dev/null
~

```