backup batch script- changing filename?

lockmac

Senior member
Dec 5, 2004
603
0
0
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
 

rasczak

Lifer
Jan 29, 2005
10,437
23
81
why not use NTBACKUP to create a backup job for that file each day of the week?
 

Mojoed

Diamond Member
Jul 20, 2004
4,473
1
81
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.
 

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
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?
 

Ns1

No Lifer
Jun 17, 2001
55,420
1,600
126
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
 

lockmac

Senior member
Dec 5, 2004
603
0
0
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!
 

lockmac

Senior member
Dec 5, 2004
603
0
0
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?
 

Engineer

Elite Member
Oct 9, 1999
39,230
701
126
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\