编写一个脚本,oracle数据库使用rman的一周的备份脚本,要求,周三做全备份,其他时间做增量备份
时间: 2024-05-22 10:12:20 浏览: 119
oracle rman备份脚本
4星 · 用户满意度95%
#!/bin/bash
# Set the Oracle Environment Variables
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
export ORACLE_SID=ORCL
# Set the backup location
export BACKUP_DIR=/u01/backup
# Get the day of the week
DAY=$(date +%A)
# Create the backup directory if it doesn't exist
if [ ! -d "$BACKUP_DIR" ]; then
mkdir "$BACKUP_DIR"
fi
# Do a full backup on Wednesday and incremental backups on other days
if [ "$DAY" == "Wednesday" ]; then
rman target / << EOF
run {
allocate channel ch1 type disk;
backup database plus archivelog;
release channel ch1;
}
exit;
EOF
else
rman target / << EOF
run {
allocate channel ch1 type disk;
backup incremental level 1 database plus archivelog;
release channel ch1;
}
exit;
EOF
fi
# Move the backup to the backup directory
mv /u01/app/oracle/fast_recovery_area/ORCL/backupset/* "$BACKUP_DIR"
# Delete backups older than 7 days
find "$BACKUP_DIR" -name "*.bkp" -mtime +7 -exec rm {} \;
阅读全文