backup script

#!/bin/bash
#####################################################
#    export the whole database use exp utility.     #
#####################################################

#########load db profile#############################
. ~/profile/c21upg10.profile

#########set nls_lang################################
db_nls_value=`sqlplus -s / as sysdba <<EOF
select userenv(‘language‘) from dual;
EXIT
EOF`
NLS_LANG=`(echo $db_nls_value | cut -d‘ ‘ -f3)`
export NLS_LANG

##########exp########################################
file_name="${ORACLE_SID}_full_`date ‘+%y%m%d‘`.dmp"
log_name="${ORACLE_SID}_imp_`date ‘+%y%m%d‘`.log"
backup_location=/u01/db_backup
exp \‘/ as sysdba\‘ file=$backup_location/$ORACLE_SID/$file_name log=$backup_location/$ORACLE_SID/$log_name full=y

##########compress and delete obsoleteness###########
gzip $backup_location/$ORACLE_SID/*.dmp

后来加了一段删除冗余代码。 这段代码中要记住的有几点

1. 设置日期

date -d "-1 week" +%y%m%d
date -d "-1 day" +%y%m%d

2. 判断shell命令执行成功与否

command ; flag=$?

if [ $flag -eq 0 ]



cur_bak=$backup_location/$ORACLE_SID/${ORACLE_SID}_full_`date ‘+%y%m%d‘`.dmp.gz
cur_bak_7=$backup_location/$ORACLE_SID/${ORACLE_SID}_full_`date -d "-1 week" +%y%m%d`.dmp.gz
cur_bak_14=$backup_location/$ORACLE_SID/${ORACLE_SID}_full_`date -d "-2 week" +%y%m%d`.dmp.gz
cur_log=$backup_location/$ORACLE_SID/${ORACLE_SID}_imp_`date ‘+%y%m%d‘`.log
cur_log_7=$backup_location/$ORACLE_SID/${ORACLE_SID}_imp_`date -d "-1 week" +%y%m%d`.log
cur_log_14=$backup_location/$ORACLE_SID/${ORACLE_SID}_imp_`date -d "-4 week" +%y%m%d`.log

if [ -a $cur_bak ] && [ -a $cur_bak_7 ] && [ -a $cur_bak_14 ] ;
then
    grep "Export terminated successfully without warnings" $cur_log >/dev/null 2>&1 ; flag1=$?
    grep "Export terminated successfully without warnings" $cur_log_7 >/dev/null 2>&1 ; flag2=$?
    grep "Export terminated successfully without warnings" $cur_log_14>/dev/null 2>&1 ; flag3=$?
    if [ $flag1 -eq 0 ] && [ $flag2 -eq 0 ] && [ $flag3 -eq 0 ] ;
    then
        mkdir $backup_location/$ORACLE_SID/temp; flag1=$?
        mv $cur_bak $backup_location/$ORACLE_SID/temp ;flag2=$?
        mv $cur_bak_7 $backup_location/$ORACLE_SID/temp ;flag3=$?
        mv $cur_bak_14 $backup_location/$ORACLE_SID/temp ;flag4=$?
        mv $cur_log $backup_location/$ORACLE_SID/temp ;flag5=$?
        mv $cur_log_7 $backup_location/$ORACLE_SID/temp ;flag6=$?
        mv $cur_log_14 $backup_location/$ORACLE_SID/temp ;flag7=$?
        if [ $flag1 -eq 0 ] && [ $flag2 -eq 0 ] && [ $flag3 -eq 0 ] && [ $flag4 -eq 0 ] && [ $flag5 -eq 0 ] && [ $flag6 -eq 0 ]  && [ $flag7 -eq 0 ] ;
        then
            rm $backup_location/$ORACLE_SID/*.gz ; flag1=$?
            rm $backup_location/$ORACLE_SID/*.log; flag2=$?
            mv $backup_location/$ORACLE_SID/temp/* $backup_location/$ORACLE_SID/; flag3=$?
            rm -r $backup_location/$ORACLE_SID/temp/; flag4=$?
            if [ $flag1 -eq 1 ] || [ $flag2 -eq 0 ] || [ $flag3 -eq 0 ] || [ $flag4 -eq 0 ];then
                echo "send email for here0"
            fi
        fi
    fi
else
    echo "send email for here1"
fi

backup script

时间: 2025-01-07 19:40:36

backup script的相关文章

Using the Windows Scheduler to run a SharePoint PowerShell Backup Script

Problem SharePoint administrators need to run regular backups using PowerShell, the STSADM tool or in Central Administration. There is no "built in" way to automate these backups. Wouldn't it be great to devise a method to automated these jobs?

backup2:backup devices

Backup Devices 是存储SQL Server 数据和Trasaction Log备份的文件,分为两种:Physical backup device 和 logical backup device.physical backup device 是指Windows OS的file,其 physical name 类似:"D:\FolderPaths\FileName.bak",也可以是远程共享网络上一个file,其physical name 类似:"\\ServerN

Odoo Auto Backup Database And Set Linux task schedualer

First ,Write Database Backup Script: pg_dump -Fc yourdatabasename > /home/yourfilepath/yourdatabasename$(data+%Y-%m-%d).dump Save it as a file name dump.sh su root user,and set schedualer job: crontab -e set every day 3:00 am auto backup database: 00

MHA 一主一从搭建

安装基本环境介绍 一主一从 MHA manager & slave  node2 192.168.56.27 Master机器 node1 192.168.56.26 VIP   192.168.56.25 配置互信 在192.168.56.26 使用ssh-keygen生成key 输入下面的命令,一路回车就行了.最后会在~/.ssh下面产生:id_rsa  id_rsa.pub两个文件. #ssh-keygen 生成信任文件: #cd ~/.ssh/ #cat id_rsa.pub >au

MHA在线切换脚本master_ip_online_change结合VIP

结合vip的主库在线切换脚本master_ip_online_change: #!/usr/bin/env perl #  Copyright (C) 2011 DeNA Co.,Ltd. # #  This program is free software; you can redistribute it and/or modify #  it under the terms of the GNU General Public License as published by #  the Fr

rman 冷备份异机迁移

rman 作为 oracle 推荐的备份.恢复方式,我们常使用它来进行异机迁移数据库. 网上的攻略都是 rman 的热备份异机迁移,相比冷备份的异机迁移需要多备份归档(未归档)日志文件.联机日志文件,操作步骤较为复杂. 如果是可以停机的数据库,更推荐使用 mount 方式下的冷备份来做异机迁移. 写了一个迁移文件,以备后用. Part1 Env { 'first database':{ 'os':'suse11' 'oracle_version':'11gr2' } 'second databa

利用tar进行完全备份、增量备份、差异备份,并控制版本号,自动删除备份文件

因业务需求,需对一个目录进行定期备份,现在使用tar进行自动备份,计划每周一次完整备份,其他每天进行增量或者差异备份,所以写出下面的脚步通过指定参数来选择备份模式.备份文件只保留最近两个完整备份版本和附属的增量或差异备份版本. [[email protected] script]# ./backup.sh          Please select the backup or delete mode,[full|diff|incr|delete|help] [[email protected]

MHA部署笔记(centos6+mysql5.6)

环境及软件版本: CentOS6.5x86_64 MySQL5.6.34编译安装版 MHA版本:mha4mysql-manager-0.56-0.el6.noarch.rpm mha4mysql-node-0.56-0.el6.noarch.rpm 节点角色: node93:10.1.20.93   默认主库 node94:10.1.20.94   从库1,原先主库宕机后可提升为主库[mha管理节点也部署在这台机器上] node95:10.1.20.95   从库2,不允许提升为主库 准备的VI

一个好用的Python备份mysql的脚本

前几天打算用Python写一个mysql脚本,上Google看了下老外写的,写的挺好的,原地址在http://tecadmin.net/python-script-for-mysql-database-backup/#,所以就给 copy过来了 1 #!/usr/bin/python 2 ########################################################### 3 # 4 # This python script is used for mysql