While doing development on a database such as a Microsoft Access .mdb or .accdb file, it’s a best practice to create a backup of the file every few hours in case you mess something up and need to revert to a prior copy.
I used to just do the CTRL+C / CTRL+V thing to make a copy of the file, but if you accidentally opened one of those copies you’d lose the info about when the file was created. That, and the files take up a lot of disk space.
What I wanted was to be able to right-click a file, choose some action and have it automatically:
- Backup the file
- Name the backup with something that includes the filename and then the date and time in YYYY-MM-DD format so I could sort by the filename to get the latest or oldest and not have to worry about the modified dates changing.
- Move the file to a .rar file to save space. (Access databases in particular are often highly compressable).
To solve my problem, I created a little dos batch file I call “BackupFile.bat” and I put it in my send to menu so that go-forward, I could just right-click a file, choose Send To and then Backup File:
Create a batch file called BackupFile.bat with these contents:
for /F "eol=; tokens=1-7 delims=/:. " %%a in ("%DATE%:%TIME%") do SET myOutput=%~n1_%%c-%%a-%%b_%%dh_%%em_%%f.%%gs%~x1
if exist "%1" (
Make sure you update the path to WinRAR above to a valid WinRAR path, or just modify that line to work with your preferred compression app.
Once you’ve created the .bat file you can quickly add it to your send to menu by clicking Start –> then type: shell:sendto and hit enter. Doing that should open your send to folder in Windows explorer.
Create a shortcut to the BackupFile.bat file in that location and you’re set.
To use, you just right-click the file you want to backup:
You’ll see the batch file appear in a command window, and then a WinRAR creating archive box appear:
When done, you’ll have a Backup folder under the folder you were in previously, and in that folder you’ll see the .RAR files you just created: