Page 1 of 1
simple copy of folder for backup fails
Posted: 22 Sep 2022 06:13
by snifferpro
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?
Re: simple copy of folder for backup fails
Posted: 22 Sep 2022 09:38
by Aacini
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:/=_%\"
Re: simple copy of folder for backup fails
Posted: 22 Sep 2022 09:42
by aGerman
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
Re: simple copy of folder for backup fails
Posted: 22 Sep 2022 10:45
by snifferpro
I executed that batch file and got nothing in "f:/TBBackup%date:/=-%
That folder / file does not exist
Re: simple copy of folder for backup fails
Posted: 22 Sep 2022 10:49
by snifferpro
I'm sorry, I just checked again and it actually created a new folder "TBBackup Thu 09-22-2022
Re: simple copy of folder for backup fails
Posted: 22 Sep 2022 10:53
by snifferpro
Can I add Time to that?
Re: simple copy of folder for backup fails
Posted: 22 Sep 2022 11:14
by aGerman
You could. However, most likely the %time% variable contains colons that have to be replaced just like the slash in %date%.
Steffen
Re: simple copy of folder for backup fails
Posted: 22 Sep 2022 13:43
by snifferpro
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.
Re: simple copy of folder for backup fails
Posted: 22 Sep 2022 14:02
by aGerman
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
Re: simple copy of folder for backup fails
Posted: 22 Sep 2022 23:14
by miskox
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