iT邦幫忙

1

cmd 可否更改資料夾名稱?

  • 分享至 

  • xImage

各位先進前輩好!
小弟有一備份批次檔會抓當天日期去建立新資料夾來備份來源端資料夾檔案,
但批次檔目前是先將目的端資料夾全清空後再建立新資料夾開始跑備份,
有點像是刪除後複製的意思,但由於這樣總是要跑很久才會跑完,
因為小檔眾多(約莫3.400萬小檔)每次windows檢索就花不少時間,
所以打算試看看mir鏡像備份試看看是否比較快,
可否在執行鏡像前或後有次檔語法可以改資料夾檔名。

例如:
原先為2024-02-05欲改成2024-02-07
而2/9日那天跑備份時,則為2024-02-07改成2024-02-09

有前輩能指教一二嗎?謝謝。

chuway iT邦新手 2 級 ‧ 2024-02-12 00:53:50 檢舉
@echo off
rem RHEL 每日22:10壓縮備份.tgz,作業時間約10分鐘
rem PC 每日23:30將備份檔傳回本地硬碟,作業時間約1分鐘
rem Onedrive自動將本地硬碟備份檔同到雲端

rem dt=20160613
set dt=%date:~0,4%%date:~5,2%%date:~8,2%

set BACKUP_DIR=E:\OneDrive\RHEL

rem 1.先備份到 E:\YYYYMMDD (日期) 資料夾
rem 2.檢查第一行 SATRT 20160312 22:22:25 (壓縮備份log第一行加註)
rem 3.將其搬到 E:\OneDrive\RHEL 中=>sync 雲端

E:
cd\
mkdir %dt%
cd %dt%

rem ftp -s:E:\CloudBox\RHEL\ftp2rhel.txt (傳回一打包檔案)
ftp -s:%BACKUP_DIR%\ftp2rhel.txt;

cd ..

rem move 20160313 E:\OneDrive\RHEL
rem 確認資料日期: 取出 START那一行第2欄資料 godate=20160612
FOR /F "tokens=2" %%a in ('find"START" /I %dt%\gobackup.log') do (set godate=%%a)
rem 如果目標資料匣存在,變成20160612.1
if exist %BACKUP_DIR%\%godate% set godate=%godate%.1
move /Y %dt% %BACKUP_DIR%\%godate%
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
nb656565
iT邦見習生 ‧ 2024-02-07 10:38:54

move <現在的資料夾名稱> <要改成的資料夾名稱>

看更多先前的回應...收起先前的回應...
邊緣人 iT邦新手 4 級 ‧ 2024-02-07 10:47:28 檢舉

nb656565大大您好,這有辦法做到自動化嗎?

SunM0on iT邦新手 5 級 ‧ 2024-02-07 11:21:55 檢舉

指令都給你了 為甚麼沒辦法自動化,可以問,但別這麼伸手吧

SunM0on iT邦新手 5 級 ‧ 2024-02-07 11:26:25 檢舉

另外我覺得你的需求應該是自動刪除舊有的備份,再自動建立新的備份,不是直接改資料夾名稱

chuway iT邦新手 2 級 ‧ 2024-02-12 00:59:34 檢舉

因為要保留每日備份,不能刪檔

1
竹本立里
iT邦好手 1 級 ‧ 2024-02-07 11:37:08
set today=%date:~0,4%_%date:~5,2%_%date:~8,2%

md %today%

move c:\temp\*.* c:\%today%\

pause
0
by2048
iT邦高手 1 級 ‧ 2024-02-07 13:55:38

建議百萬個檔案不要用這種模式備份
一般會用rsync(或備份軟體) 比對內容有無變動再做備份較適合

0
PIZZ
iT邦新手 3 級 ‧ 2024-02-07 15:44:40

ren C:\TEST(<<<要改名的資料夾路徑+名稱) test(新資料夾名稱)

存成.bat就可以批次了


另外目前我用備份批次是做robocopy(差異):

obocopy "來源路徑" "目的路徑" /TEE /E /S /mir /w:2 /R:2

要刪除原檔的話,下一行做刪除原路徑檔案

rmdir /s /q 來源路徑\*.*

move那個應該是搬移吧??

0
hank_itman
iT邦新手 1 級 ‧ 2024-02-08 10:31:14

用XCOPY比對過複製也可以

xcopy Y:*.* E:\ /S /D /Y /C

0
com
iT邦新手 4 級 ‧ 2024-02-09 17:25:47

DOS用md跟move,自動化可以寫bat,排程可以用windows內建。
linuxdk3u3h0 考網頁設計

0
kalylcie
iT邦見習生 ‧ 2024-02-24 11:10:09

In this batch file, we use the date /t command to get today's date, and then format it into YYYY-MM-DD. Next, we use the ren command to change the name Geometry Dash of the destination folder to today's date. Finally, we use the robocopy command to perform an image backup.

我要發表回答

立即登入回答