linux和unix下面使用shell可以很方便實現,如果windows環境下可以結合計劃任務實現
1.建立備份目錄d:\backup, 建立批處理命令Bak.bat,編寫備份指令碼
exp user/passwd@orcl DIRECT=Y BUFFER=100000 FILE=D:\backup\scdd%date:~0,10% OWNER=('scdd') LOG=D:\backup\data.log forfiles /p "D:\backup" /s /m *.dmp /d -3 /c "cmd /c del @path"
說明:
exp命令是oracle提供的dump備份命令,其中的%date:~0,10%是DOS裡取日期的命令,例如:C:\Users\qyy>echo %date:~0,10%得到2016-11-30
forfiles是windows的檔案尋找命令,尋找在backup,dmp尾碼產生三天的檔案,找到後執行刪除操作
2.Windows定時任務每日自動執行批次檔 3.保留最近三天的檔案,自動刪除以前日期的備份檔案
forfiles參數說明:
/P 可是搜尋的路徑。在我們這裡就是要在哪個目錄尋找要刪除的檔案
/M 根據搜尋掩碼搜尋檔案。預設為*,如果要找備份處dump檔案,格式為*.dmp
/D 檔案修改時間在某個時間之前或者之後。-3 表示3天之前的檔案。
/s 包含子目錄
/C 表示為每個檔案執行的命令,如果要刪除該檔案可以為"cmd /c del /F /s /q @file"。其中變數@file表示該檔案名稱 f s q表示強制靜默刪除可以不用;cmd /c表示執行字串指定的命令然後終斷
其中@file可以返還如下結果,我們這裡用@path
@file - returns the name of the file.
@fname - returns the file name without extension.
@ext - returns only the extension of the file.
@path - returns the full path of the file.
@relpath - returns the relative path of the file.
@isdir - returns "TRUE" if a file type is a directory, and "FALSE" for files. @fsize - returns the size of the file in bytes.
@fdate - returns the last modified date of the file.
@ftime - returns the last modified time of the file
以上所述是小編給大家介紹的Windows系統下Oracle資料庫每天自動備份,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對雲棲社區網站的支援!