windows常用批处理脚本(Windows common batch script)

1、拷贝windows远程服务器上的指定文件夹到本地服务器指定目录批处理脚本如下

#使用管理员账号密码登录,拷贝文件

#bak文件夹需是共享文件夹

net use \\192.168.1.10\ipc$ 123456/user:adminstrator

xcopy \\192.168.1.10\bak\gsdebug\*.* D:\bak\gsdebug /D /E /Y /H /K

net use \\192.168.1.10\ipc$ /delete 

2、windows下删除指定文件夹下的文件,保留5天,批处理脚本如下

forfiles /p “D:\bak\gsdebug” /s /m *.* /d -5 /c “cmd /c del @path”

/p 指定的路径

/s 包括子目录

/m 查找的文件名掩码

/d 指定日期,有绝对日期和相对日期, 此处-7指当前日期 的7天前  

/c 运行的命令行   表示为每个文件执行的命令。命令字符串应该用双引号括起来。 

@path    – 返回文件的完整路径。

3、上传到阿里云OSS,批处理脚本如下

下载ossutil64.exe命令,配置.ossutilconfig文件

ossutil64.exe cp –config-file C:\ossutil64\.ossutilconfig -r D:\bak\  oss://csbak/bak –update

————————

1. Copy the specified folder on the windows remote server to the specified directory on the local server. The batch script is as follows

#Log in with the administrator account and password and copy the file

#Bak folder needs to be a shared folder

net use \\192.168.1.10\ipc$ 123456/user:adminstrator

xcopy \\192.168.1.10\bak\gsdebug\*.* D:\bak\gsdebug /D /E /Y /H /K

net use \\192.168.1.10\ipc$ /delete 

2. Delete the files in the specified folder under windows and keep them for 5 days. The batch script is as follows

forfiles /p “D:\bak\gsdebug” /s /m *.* /d -5 /c “cmd /c del @path”

/P specified path

/S includes subdirectories

/M find file name mask

/D specifies the date, including absolute date and relative date. Here -7 refers to 7 days before the current date

/The command line run by C represents the command executed for each file. The command string should be enclosed in double quotes.

@Path – returns the full path of the file.

3. Upload to alicloud OSS. The batch script is as follows

Download ossutil64 Exe command, configuring Ossutilconfig file

ossutil64.exe cp –config-file C:\ossutil64\.ossutilconfig -r D:\bak\  oss://csbak/bak –update