creating powershell script to backup a file and append the date

Sam Carleton picture Sam Carleton · Sep 8, 2010 · Viewed 22.8k times · Source

Currently I have a one line batch file to back up a file. I run it manually when I need to back up a file. The only thing I would like to add to it is the current date. Here is what I have:

xcopy /W /Y ACTIVE.DB ACTIVE.DB.BACKUP

the destination file should simply be ACTIVE.DB.BACKUP.YYYYMMDD. How would I go about creating a script that will allow me to double click on it from Windows Explorer and make the xcopy happen?

Answer

Keith Hill picture Keith Hill · Sep 9, 2010

Just to point out that you can do this with Copy-Item e.g.:

Set-Location $path
Copy-Item ACTIVE.DB "ACTIVE.DB.$(get-date -f yyyyMMdd)" -Force -Confirm

If you're going for robust then I'd use robocopy.exe.