Windows system backup mongodb and forfiles delete backup files and folders

windows系统:

新建delete.bat文件,写入如下内容

rem  删除D:\dump\BackupDB目录下3天前的文件及文件夹

forfiles /p D:\dump\BackupDB /d -3  /c "cmd /c if @isdir==TRUE (rmdir /q /s @path) else (del /f @path)"

The if condition means: if it is a folder, use rmdir to delete it; if it is a file, use the del command to force it to be deleted.

.bat文件内容:

rem  备份MongoDB数据

@echo off

D:
cd D:\mongodbserver2\bin

md %date:~0,4%-%date:~5,2%-%date:~8,2%

mongodump -h 192.168.19.12:27011 -d test -o D:\dump\BackupDB\%date:~0,4%-%date:~5,2%-%date:~8,2%

 

Parameter list:
    /p pathname indicates the path to start searching. The default folder is the current working directory (.).
    /m searchmask Searches files based on the search wildcard specified by searchmask. The default search mask is '*'.
    /s directs forfiles to recurse into subdirectories. Like "DIR /S".
    /c command indicates the command to be executed for each matched object. Command strings should be enclosed in double quotes. The default command is "cmd /c echo @file". The following variables can be used in command strings:
                        @file - Returns the filename (only the filename).
                        @fname - Returns the filename without extension.
                        @ext - Returns only the file extension.
                        @path - Returns the full path to the file (including file name).
                        @relpath - Returns the relative path to the file.
                        @isdir - Returns "TRUE" if the file type is a directory; "FALSE" if it is a file.
                        @fsize - Returns the file size in bytes.
                        @fdate - Returns the date the file was last modified.
                        @ftime - Returns the time the file was last modified.

Guess you like

Origin blog.csdn.net/FORLOVEHUAN/article/details/112883543