---
# System prepended metadata

title: Windows 使用 CMD 備份
tags: [Programming]

---

Windows 使用 CMD 備份
===

###### tags: `Programming`

### 進階設定
- 最低可調整成 1 分鐘(dropdown 之後，手動輸入)

### 設定排程
- 工作排程器
    - ![](https://i.imgur.com/YgKcKH8.png)

- 新增工作
    - ![](https://i.imgur.com/xZMmrgQ.png)

- 設定時間
    - ![](https://i.imgur.com/biGDdU5.png)
    - ![](https://i.imgur.com/CUvLe0I.png)


- 設定執行內容
    - ![](https://i.imgur.com/12wBlB4.png)
    - ![](https://i.imgur.com/5q65lKs.png)


- 其他設定
    - ![](https://i.imgur.com/6IxLkkI.png)


### 批次檔內容
- Today
```c=
SET y=%date:~0,4%
SET m=%date:~5,2%
SET d=%date:~8,2%

xcopy d:\{FilePath}\%y%%m%%d%MergedDataLog.csv \\{FilePath}}


```


- Yesterday
```c

    echo wscript.echo dateadd("d",-1,date) >%tmp%\tmp.vbs
    for /f "tokens=1,2,3 delims=/- " %%i in ('cscript /nologo %tmp%\tmp.vbs') do set y=%%i
    for /f "tokens=1,2,3 delims=/- " %%i in ('cscript /nologo %tmp%\tmp.vbs') do set m=%%j
    for /f "tokens=1,2,3 delims=/- " %%i in ('cscript /nologo %tmp%\tmp.vbs') do set d=%%k
    if %m% LSS 9 set m=0%m%
    if %d% LSS 9 set d=0%d%

echo %y%
echo %m%
echo %d%


xcopy d:\{FilePath}\%y%%m%%d%MergedDataLog.csv \\{DestFilePath}\Log


```