+[HELP] With Date Stamp Daily Backup+

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

+[HELP] With Date Stamp Daily Backup+

#1 Post by Dos_Probie » 21 Jun 2012 12:46

Have the need to backup all my Desktop files and folders at the end of the day to my thumbdrive, see below working code that I have so far, Anyway my problem is that I would like NOT having to enter in NAME of the folder(See lines 2,3,4) but have the Folder name done automatically in my code
per the format of line 1.

Thanks for the help... :)

Code: Select all

@echo off
title [ + DAILY BACKUP TO THUMBDRIVE + ]

::LINE 1) - Backup Folder-<mo-day-yr>::
md e:\%date:~4,2%-%date:~7,2%-%date:~10,4%

::LINE 2) - Backup to ThumbDrive::
xcopy /yisdef "%userprofile%\desktop\*.%1" "e:\06-21-2012">nul

::LINE 3) - Zip Backup::
"%programfiles%\7-Zip\7z.exe" a "e:\06-21-2012.7z" "e:\06-21-2012">nul

::LINE 4) - Clean-Up::
rd "e:\06-21-2012"/q/s

exit

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: +[HELP] With Date Stamp Daily Backup+

#2 Post by Squashman » 21 Jun 2012 15:08

You have the code to create the directory now use it as your destination!
What makes you think you can't use the same code you used to create the directory for the destination directory in your XCOPY command?

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: +[HELP] With Date Stamp Daily Backup+

#3 Post by Fawers » 21 Jun 2012 16:14

I think this will meet your needs.

Code: Select all

@echo off
title [ + DAILY BACKUP TO THUMBDRIVE + ]
set "dateNow=%date:~4,2%-%date:~7,2%-%date:~10,4%"
ECHO dateNow = %dateNow%
PAUSE
::remove ECHO and PAUSE lines if output is the one desired.

::LINE 1) - Backup Folder-<mo-day-yr>::
md e:\%dateNow%

::LINE 2) - Backup to ThumbDrive::
xcopy /yisdef "%userprofile%\desktop\*.%1" "e:\%dateNow%">nul

::LINE 3) - Zip Backup::
"%programfiles%\7-Zip\7z.exe" a "e:\%dateNow%.7z" "e:\%dateNow%">nul

::LINE 4) - Clean-Up::
rd "e:\%dateNow%"/q/s

exit

Just like Squashman said, you can use that piece of code on all 3 remaining lines of the code; this avoids "hard" coding.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: +[HELP] With Date Stamp Daily Backup+

#4 Post by Dos_Probie » 21 Jun 2012 18:44

Ok Thanks Guys! After a few beers I got it now...Also used set variable to cut down on code...See below. :D

Code: Select all

@echo off
title DESKTOP BACKUP WITH DATE STAMP
set DirDate=%date:~4,2%-%date:~7,2%-%date:~10,4%
md "e:\%DirDate%"&xcopy /yisdef "%userprofile%\desktop\*.%1" "e:\%DirDate%">nul
7z.exe a "e:\%DirDate%.7z" "e:\%DirDate%">nul&rd "e:\%DirDate%"/q/s
exit

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: +[HELP] With Date Stamp Daily Backup+

#5 Post by Squashman » 21 Jun 2012 19:11

Using the ampersand the way you are using it just makes your code unreadable.
It is really not necessary to use either.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: +[HELP] With Date Stamp Daily Backup+

#6 Post by Dos_Probie » 21 Jun 2012 20:03

The ampersand just saved me some extra code lines and it LQQKS and Works great and I read it just fine, especially since I wrote it for my personal backup and also now that I have encrypted it via my batch compiler with an icon and pinned to my taskbar no one will be able to open it up to read it anyway... :mrgreen:

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: +[HELP] With Date Stamp Daily Backup+

#7 Post by Fawers » 21 Jun 2012 20:08

Dos_Probie wrote:(...) and also now that I have encrypted it via my batch compiler with an icon and pinned to my taskbar no one will be able to open it up to read it anyway... :mrgreen:

Unless someone with some knowledge on these compilers uses your machine.
These "compilers" send the original .cmd/.bat to %temp% when the .exe is double clicked; while the dos window is opened, anyone can read the source code. :P

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: +[HELP] With Date Stamp Daily Backup+

#8 Post by Dos_Probie » 21 Jun 2012 20:27

True, thats what most apps do is use the temp, but I just compile my batch files to give more of a professional look anyway.. 8)

As they say "Locks only keep the honest people out"

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: +[HELP] With Date Stamp Daily Backup+

#9 Post by Squashman » 22 Jun 2012 06:22

Dos_Probie wrote:The ampersand just saved me some extra code lines and it LQQKS and Works great and I read it just fine, especially since I wrote it for my personal backup and also now that I have encrypted it via my batch compiler with an icon and pinned to my taskbar no one will be able to open it up to read it anyway... :mrgreen:

Not quite understanding what you mean by when you say it saved you some extra code lines. All it did was make your batch file two lines shorter. That is about it. Your overall batch file size is technically only TWO BYTES smaller.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: +[HELP] With Date Stamp Daily Backup+

#10 Post by Dos_Probie » 22 Jun 2012 14:05

My first post:"Have the need to backup all my Desktop files and folders at the end of the day to my thumbdrive"..
Squashman post: "Not quite understanding what you mean by when you say it saved you some extra code lines"..
"Using the ampersand the way you are using it just makes your code unreadable"..



Squashman, sorry if you found my code hard to read or understand for you. Below is my final batch
Now let's do the Math.

Code: Select all

@echo off&color a&mode con:cols=75 lines=20&title[ DESKTOP BACKUP WITH DATE STAMP ]
set DirDate=%date:~4,2%-%date:~7,2%-%date:~10,4%
md "e:\%DirDate%"&xcopy /yisdef "%userprofile%\desktop\*.%1" "e:\%DirDate%">nul
7z.exe a "e:\%DirDate%.7z" "e:\%DirDate%">nul&rd "e:\%DirDate%"/q/s
exit

1. 2 lines less - @echo line grouped commands together on oneliner
2. 4 lines less - Left off the usual remarks/comments.
3. 2 lines less - Main code body was consolated together - saved 2 lines
4. 5 lines less - No dbl spacing between code lines.
================+
13 LINES LESS!

So I quess for the visually impaired or if I had been contracted to do this batch for someone I would have done everthing in Uppercase, lots of comments for better understanding of whats going on, the main body of code would have been dbl spaced and commands on seperate lines for easier reading, xcopy switches would also have had the fwd slash after each switch instead being all bunched together making for better eye candy and improved comprehension...

My bad if I didn't make my orginal post clear enought to you that this batch was just being written for my own purposes to back-up all my desktop crap at the end of the day. So if i didnt you can spank me.. :mrgreen:

Post Reply