我有6个文件夹,其数据库备份文件名为 COMPANY _Backup_ DATE .rar。我想将每个最后的文件复制到一个文件夹中,压缩并复制到我的电脑上。
SET FECHA=%date:~6,4%%date:~3,2%%date:~0,2%
rem Company1
XCOPY D:\BackupBBDD\COMPANY1\COMPANY1_backup_*.bak D:\BackupBBDD\CopiasBBDD\ /d /s
...
rem Company6
XCOPY D:\BackupBBDD\COMPANY6\COMPANY6_backup_*.bak D:\BackupBBDD\CopiasBBDD\ /d /s
rem rar and delete the folder
rar a -m5 -df -y Backup_RAR_%FECHA%.rar CopiasBBDD
rem copy to my pc
copy D:\BackupBBDD\Backup_RAR_%FECHA%.rar \\tsclient\D
每次执行此批处理时,都会复制每个文件夹的所有文件。备份文件每周创建一次,文件夹“CopiasBBDD”创建此脚本的开头并在最后删除。
答案 0 :(得分:0)
最后,我创建了一个回答我问题的代码。
SET FECHA=%date:~6,4%%date:~3,2%%date:~0,2%
SET DESTDIR=D:\BackupBBDD\CopiasBBDD\
@rem verify folders and copy last file.
@echo off
setlocal
set srcDir=D:\BackupBBDD\COMPANY1
set lastmod=
pushd "%srcDir%"
for /f "tokens=*" %%a in ('dir /b /od 2^>NUL') do set lastmod=%%a
if "%lastmod%"=="" echo Could not locate files.&goto :eof
xcopy "%lastmod%" "%DESTDIR%"
...
set srcDir=D:\BackupBBDD\COMPANY6
set lastmod=
pushd "%srcDir%"
for /f "tokens=*" %%a in ('dir /b /od 2^>NUL') do set lastmod=%%a
if "%lastmod%"=="" echo Could not locate files.&goto :eof
xcopy "%lastmod%" "%DESTDIR%"
rem RAR and copy
rar a -m5 -df -y Backup_RAR_%FECHA%.rar CopiasBBDD
xcopy D:\BackupBBDD\Backup_RAR_%FECHA%.rar \\tsclient\D