Oracle uses the batch file expdp for regular backup

bat file:

@echo off 
echo ================================================ 
echo  Windows环境下Oracle数据库的自动备份脚本
echo  1. 使用当前日期命名备份文件。
echo ================================================
::对应用户名
set USER=QXXXXX
::对应用户的密码
set PASSWORD=QXXXXX
::导出数据(根据日期加时分秒来命名备份文件)
expdp %USER%/%PASSWORD% directory=qmysptbackup dumpfile=yxhl_%date:~0,4%%date:~5,2%%date:~8,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%.dmp logfile=yxhl_%date:~0,4%%date:~5,2%%date:~8,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%.log schemas=%USER%

::如果报错LRM-00112: 参数'logfile'不允许有多个值。 则是上面时间格式输出有问题,有空格,输出了两个值,加上下划线_ 即可 (在date和time之间加下划线 )
::yxhl_%date:~0,4%%date:~5,2%%date:~8,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%.log

Change it to bat format, add it to the task plan , the prerequisite setting of the script:
create a logical directory:

SQL> create directory data_dir as '/home/oracle/dmp/user';

Directory created.

Use the sys administrator to give your designated users the authority to operate in the directory. /directory empower

SQL> grant read,write on directory data_dir to user;

Grant succeeded.

The result after execution:
Insert picture description here
Insert picture description here
Insert picture description here

It is also worth noting that the value of this directory must be changed in Oracle.

create or replace directory dumpdir as '/home/dumpfiles';

It’s not right to change it directly in the bat outside,,,
Insert picture description here

Reference:
https://www.cnblogs.com/promise-x/p/7477360.html
https://mhl.xyz/Oracle/directory.html
https://www.cnblogs.com/luck666/p/10253686. html

split line===
About the deletion:
shell:

find /data01/backup/ -mtime +15 -name "user*.dump" -exec rm -rf {
    
    } \;  #删除前15天的数据
#find 对应目录 -mtime +天数 -name "文件名" -exec rm -rf {} \

powershell:

set DATADIR=F:\app\Administrator\admin\orcl\dpdump\
::删除7天前的备份。  
forfiles /p %DATADIR% /s /m HBGYDX*.DUMP /d -7 /c "cmd /c del @path"

Today I came across a pure dockerfile in a docker environment. There is no find instruction. To delete the file delFile.sh older than 30 days

#!/bin/bash

#创建文本
for i in `seq 1 40`
do
        touch `date -d "-$i day" +%Y%m%d`.txt
done

#删除过去30天的文件   20201010  今天20201109
before30Day=$(date -d "-30 day" +%Y%m%d)

for i in `ls *.txt`
do
	# ${i:0:8}截取前8位 , if里面双方变量要加双引号,否则报错
        if [ "${i:0:8}" -le "$before30Day" ];then
                echo "该文件是30天之前的: $i"
                #rm -f $i
        fi
done

Insert picture description here

Another person’s writing:
Insert picture description here

At 11:50:10 on February 19, 2021, let's
talk about another format. Draw a scoop according to gourd

xx-logstssh-2021.01.29.log
xx-logstssh-2021.02.09.log
#!/bin/bash
before7Day=$(date -d "-7 day" +%Y%m%d)

for i in `ls *.log`
do
		#sed不支持pcre表达,比如 \d
        compareDate=`echo $i | sed -r 's#.*([0-9]{4})\.([0-9]{2})\.([0-9]{2}).*#\1\2\3#'`
        if [ "$compareDate" -lt "$before7Day" ];then
                echo "该文件是7天之前的: $i"
                #rm -f $i
        fi
done

Insert picture description here

Guess you like

Origin blog.csdn.net/Nightwish5/article/details/109303422