weekly backup with retention time & UNC path

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%"

:: need to specify is it a folder or file to xcopy hence the "echo f"
echo f | xcopy "C:\FILE.xyz" "\\UNC\PATH\FILE_%datestamp%.net" /Y /C

::map unc to first available letter to feed forfiles (forfiles can't handle unc paths)
PushD "\\UNC\PATH\" &&(
    forfiles -s -m *.* -d -183 -c "cmd /c del /q @path"
     ) & PopD

Comments