• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

backup batch script- changing filename?

lockmac

Senior member
Hi guys.

I need to create a simple batch script that will backup of a file every half day.

I am going to use windows task manager to actually run the file, I just need to create a script that will copy the file.

I am fine with xcopy, but how do I make it so it actually doesnt overwrite the file, and creates a copy of the file with a different name (e.g. 01_06_2009-firstdayhalf) or something similar?

Any help appreciated.

Cheers
 
Originally posted by: lockmac
Hi guys.

I need to create a simple batch script that will backup of a file every half day.

I am going to use windows task manager to actually run the file, I just need to create a script that will copy the file.

I am fine with xcopy, but how do I make it so it actually doesnt overwrite the file, and creates a copy of the file with a different name (e.g. 01_06_2009-firstdayhalf) or something similar?

Any help appreciated.

Cheers

Use the rename command (ren), first, then xcopy it.
 
Let's say you have a file called "date.txt" that you wanted to backup with a date in the name as well as "halfday" or "morning" added.

You could have two batch files (one for halfday and one for morning) like the following:


copy date.txt date%date:~4,2%-%date:~7,2%-%date:~10%-halfday.txt

The above line would copy date.txt to date07-01-2009-halfday.txt

copy date.txt date%date:~4,2%-%date:~7,2%-%date:~10%-morning.txt

The above line would copy date.txt to date07-01-2009-morning.txt

Multiple files (wildcards also work)...

copy c:\batch\*.* c:\batch\backups\*%date:~4,2%-%date:~7,2%-%date:~10%-halfday.*

This would copy all files from the c:\batch folder into c:\batch\backups and add the current date-halfday:

i.e. copying *.* would copy all of the files and add the date-halfway inbetween *07-01-2009-halfday.*

If you had a file sample.exe, it would become sample07-01-2009-halfday.exe using the wildcard copy.



Is this what you are looking for?
 
I actually just ran this script yesterday...

del E:\Images\Older_C.dat
del E:\Images\Older_C.xml

rename E:\Images\Old_C.dat Older_C.dat
rename E:\Images\Old_C.xml Older_C.xml

rename E:\Images\Drive_C.dat Old_C.dat
rename E:\Images\Drive_C.xml Old_C.xml

?C:\Program Files\Runtime Software\DriveImage XML\dixml.exe? /bc /tE:\Images\Drive_C /r- /s- /c /v
 
Originally posted by: Engineer
Let's say you have a file called "date.txt" that you wanted to backup with a date in the name as well as "halfday" or "morning" added.

You could have two batch files (one for halfday and one for morning) like the following:


copy date.txt date%date:~4,2%-%date:~7,2%-%date:~10%-halfday.txt

The above line would copy date.txt to date07-01-2009-halfday.txt

copy date.txt date%date:~4,2%-%date:~7,2%-%date:~10%-morning.txt

The above line would copy date.txt to date07-01-2009-morning.txt

Multiple files (wildcards also work)...

copy c:\batch\*.* c:\batch\backups\*%date:~4,2%-%date:~7,2%-%date:~10%-halfday.*

This would copy all files from the c:\batch folder into c:\batch\backups and add the current date-halfday:

i.e. copying *.* would copy all of the files and add the date-halfway inbetween *07-01-2009-halfday.*

If you had a file sample.exe, it would become sample07-01-2009-halfday.exe using the wildcard copy.



Is this what you are looking for?

Exactly what im looking for. Cheers!
 
Just quickly, with your second example of a directory, what if I wanted to just create the directory with the date name, and keep all subfolders and filenames in tact?

E.g.. the folder would be date-07-06-09-halfday or something similar?
 
Originally posted by: lockmac
Just quickly, with your second example of a directory, what if I wanted to just create the directory with the date name, and keep all subfolders and filenames in tact?

E.g.. the folder would be date-07-06-09-halfday or something similar?




c:
cd \yourfolderhere
md date-%date:~4,2%-%date:~7,2%-%date:~10%-halfday
copy c:\backupfolder\*.* c:\yourfolderhere\date-%date:~4,2%-%date:~7,2%-%date:~10%-halfday\



 
Back
Top