simple copy of folder for backup fails

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
snifferpro
Posts: 6
Joined: 10 Dec 2017 05:35

simple copy of folder for backup fails

#1 Post by snifferpro » 22 Sep 2022 06:13

I originally had a powershell script to copy 2 folders for backup.

After the most recent win 11 update, the script fails to run so I decided to just make a quick batch file
to copy my thunderbird profiles folder to different drive for backup purposes.

Here is the simple command in a batch file:

Code: Select all

@echo

xcopy c:\users\sniff\AppData\Roaming\Thunderbird\Profiles F:\TBBackup%date%\
The results
ECHO is on.

C:\Users\sniff\Desktop>xcopy c:\users\sniff\AppData\Roaming\Thunderbird\Profiles F:\TBBackupThu 09/22/2022\
Invalid number of parameters

C:\Users\sniff\Desktop>pause
Press any key to continue . . .

Can someone assist?
Last edited by aGerman on 22 Sep 2022 09:27, edited 1 time in total.
Reason: formatting

Aacini
Expert
Posts: 1920
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: simple copy of folder for backup fails

#2 Post by Aacini » 22 Sep 2022 09:38

The %date% variable include slashes that are not valid in file/folder names. You may use:

Code: Select all

xcopy c:\users\sniff\AppData\Roaming\Thunderbird\Profiles F:\TBBackup%date:/=_%\
You must also enclose in quotes any name that may include spaces, like the date:

Code: Select all

xcopy "c:\users\sniff\AppData\Roaming\Thunderbird\Profiles" "F:\TBBackup%date:/=_%\"

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: simple copy of folder for backup fails

#3 Post by aGerman » 22 Sep 2022 09:42

Your local expansion of %date% contains both spaces (which require quoting) and slashes (which are invalid characters in file and folder names).

Furthermore:
- I guess your @echo should have been @echo off.
- You didn't specify any options for XCOPY which is most likely not what you need.
- XCOPY is largely superseded by ROBOCOPY for many years now.

Code: Select all

robocopy "%appdata%\Thunderbird\Profiles" "F:\TBBackup%date:/=-%"  /e /r:0 /w:0
Steffen

EDIT Aacini has been quicker :lol:

snifferpro
Posts: 6
Joined: 10 Dec 2017 05:35

Re: simple copy of folder for backup fails

#4 Post by snifferpro » 22 Sep 2022 10:45

I executed that batch file and got nothing in "f:/TBBackup%date:/=-%

That folder / file does not exist

snifferpro
Posts: 6
Joined: 10 Dec 2017 05:35

Re: simple copy of folder for backup fails

#5 Post by snifferpro » 22 Sep 2022 10:49

I'm sorry, I just checked again and it actually created a new folder "TBBackup Thu 09-22-2022

snifferpro
Posts: 6
Joined: 10 Dec 2017 05:35

Re: simple copy of folder for backup fails

#6 Post by snifferpro » 22 Sep 2022 10:53

Can I add Time to that?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: simple copy of folder for backup fails

#7 Post by aGerman » 22 Sep 2022 11:14

You could. However, most likely the %time% variable contains colons that have to be replaced just like the slash in %date%.

Steffen

snifferpro
Posts: 6
Joined: 10 Dec 2017 05:35

Re: simple copy of folder for backup fails

#8 Post by snifferpro » 22 Sep 2022 13:43

And the code to add that to the code in number 3 above would be?

Sorry, but I haven't use dos commands for many many years.

Seems that old coding is still one of the best ways to go as DOS has hardly changed over the years.

Thanks in advance.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: simple copy of folder for backup fails

#9 Post by aGerman » 22 Sep 2022 14:02

Seems that old coding is still one of the best ways to go
Alright. So, then it seem you would like to learn it. If you look at how Aacini and I replaced the slashes in %date%, how do you think you would replace the colons in %time%?

Steffen

miskox
Posts: 633
Joined: 28 Jun 2010 03:46

Re: simple copy of folder for backup fails

#10 Post by miskox » 22 Sep 2022 23:14

I would add this: use YYYYMMDD-hh-mm-ss and not DD-MM-YYYY-hh-mm-ss so your folders will be correctly sorted. And maybe avoid using day names.

If you use YYYYMMDD (or YYYY-MM-DD - you decide what to use to make it easier for reading) your folders will be sorted by date and you will find the one you need faster:

Code: Select all

Backup_2022-08-02_00-12-34 (august)
Backup_2022-08-03_00-12-34 (august)
Backup_2022-09-02_00-12-34
Backup_2022-09-03_01-12-34
Backup_2022-09-04_00-12-34
Backup_2022-09-05_00-12-34
Backup_2022-09-06_00-12-34
Backup_2022-09-07_00-12-34
If you use DD-MM-YYYY:

Code: Select all

Backup_02-08-2022_00-12-34 (august)
Backup_02-09-2022_00-12-34
Backup_03-08-2022_00-12-34 (august)
Backup_03-09-2022_01-12-34
Backup_04-09-2022_00-12-34
Backup_05-09-2022_00-12-34
Backup_06-09-2022_00-12-34
Backup_07-09-2022_00-12-34
Saso

Post Reply