5.3 Pre script example (Linux Shell Script)

#!/bin/bash
#发送通知邮件
echo "Backup is about to start" | mail -s "Backup Notification" [email protected]

#检查存储空间
REQUIRED_SPACE=1000000  
#需要的空间大小(以KB为单位)
AVAILABLE_SPACE=$(df /backup | tail -1 | awk '{print $4}')

if [ "$AVAILABLE_SPACE" -lt "$REQUIRED_SPACE" ]; then
    echo "Not enough space for backup" | mail -s "Backup Warning" [email protected]
    exit 1
fi
#暂停相关服务
service myapp stop
#拷贝需要备份的目标目录到备份目录
\cp -r /myapp/datadir /backup && cd /backup && tar --exclude='./backupfile.tar.gz' -czvf backupfile.tar.gz . 

Last updated