Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use bat to copy the sql file with date as file name generated on the same day.

Shulou Source: shulou.com Published: 2022-06-02 20:04:22 09月29日 Update

1. Make use of the automatic backup function of SqlServer to back up the data automatically, and the file format is as follows:

Db_backup_2010_01_27_0030.bak

two。 Edit bat script

@ echo off

Echo date:~0,4%%date:~5,2%%date:~8,2%

Del h:\ backup_db* / Q

Rd / s / QH:\ backup_db

Xcopy / e d:\ backup_db\ dbbackup%date:~0,4%%date:~5,2%%date:~8,2%_00*.bak h:\ backup_db

Note:

% date:~0,4% takes the date file and takes 4 digits from bit 0, that is, the Arabic numeral of the year.

% date:~5,2% takes 2 digits back from the fifth place, that is, the month

% date:~8,2% starts at No. 8 and goes back to 2 digits, that is, the day of the month.

"*" dos wildcard, all characters of any length, but only file names or extensions; "?" The dos wildcard replaces any character, but only the file name or extension; the "*. *" global wildcard refers to any file. Del h:\ backup_db\ * / Q deletes all files under the folder. Rd / s / QH:\ backup_db delete the folder.

Tags: File backup wildcard file name character extension folder global function year data month format comment script length Arabic numeral face Allah date Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Redmi Huawei Xiaomi