how to restore with batch file in windows - batch-file

I am solving some problems, two of the are backup and restore file with batch file.
I have found out using xcopy command to backup files,
xcopy "%programfiles(x86)%\VMware" "C:\Backup" /s /c /d /e /h /i /r /y
but I still have some problems with the restore the backup files which should restore in a new folder and restore in an existing folder.
I searched on some website, some code use the same xcopy command and changed source/destination directory to restore file. Is there a command for restore or everyone changes their directory to restore files?

You have to use robocopy for that. I have successfully implemented using that. You can use xcopy if you want. During backup you can save the backups inside a folder which is named based on current date and time. You can find last or range of files and folders in the backup directory. Which you need to mirror in the destination directory

Related

Create a folder with batch file in c:\Program Files(x86)\

I am trying to make an installer and i need to create a folder in Program Files (x86).
I created a batch file with the following code:
#echo off
copy /s "c:\Users\%USERNAME%\Desktop\MagicPanelInst\magicpanel" "c:\Program Files (x86)\Common Files\Adobe\CEP\extensions\"
I pretend to copy from magicpanel from the source to the already existing folder extensions in the target...
But is created in c: a new folder called Program Files (x86) with all the directories described above, instead of copy the magicpanel folder to the existing one.
Any help please?
Now it is working with the below code.
xcopy /s "c:\Users\%USERNAME%\Desktop\MagicPanelInst\magicpanel" "%programfiles(x86)%\Common Files\Adobe\CEP\extensions\magicpanel" /i
Or even better:
xcopy /s "%UserProfile%\Desktop\MagicPanelInst\magicpanel" "%CommonProgramFiles(x86)%\Adobe\CEP\extensions\magicpanel" /i
Thank you all for the help.

Move a Folder and Subfolders to another Folder using Batch or VBS

I'm trying to automatically move the subfolders and files from my Dropbox folder on my F: Drive to a separate folder on the same drive, therefore emptying my Dropbox and freeing up space in it while backing up the files.
I tried this in Batch:
MOVE /-Y "F:\Dropbox\files\camera" "F:\backup\Camera\"
pause
but I keep getting Access Denied even when running as Administrator.
I also tried this in VBS:
With CreateObject("Scripting.FileSystemObject")
.MoveFile "F:\Dropbox\files\camera*", "F:\backup\Camera\"
End With
but I only got Path Not Found from that.
So pretty much I'm a bit stumped, or overlooking something obvious, But basically I just want to make a small script in vbs or batch that allows me to move all the sub-folders and files from F:\Dropbox\files\camera\ to F:\backup\camera\ so I can set it as a scheduled task and let it run each day so that it empties my Dropbox folder(and therefore my Dropbox account) of all files and folders and backs them up.
Any help would be appreciated, I have already searched a number of different options and none seems to work specifically for my purpose.
I suggest using ROBOCOPY instead of MOVE.
I have a similar backup script that uses it.
See:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
#ECHO OFF
ROBOCOPY /E /MOVE "F:\Dropbox\files\camera" "F:\backup\Camera\"
MKDIR "F:\Dropbox\files\camera"
Options:
/E : Copy Subfolders, including Empty Subfolders.
/MOVE : Move files and dirs (delete from source after copying).
Because of the /MOVE switch, I need to re-create the source directory because ROBOCOPY moves it to the destination directory. ROBOCOPY, by default, will retry the operation if it fails. See the /R:n and /W:n options to customize it. Also, the command will print a lot of info messages to the terminal, but you can customize it using the ROBOCOPY's logging options (ex. /NJH, /NJS, etc).
For the "Access Denied" error, make sure that:
You have write access to the destination folder
(Test by creating a batch file with just MKDIR "F:\backup\Camera\some_file.txt")
(Test by creating a batch file with just MKDIR "F:\backup\Camera\some_folder")
The files being moved are not being used or opened anywhere prior to running the script
(Ex. It's not opened in the Dropbox app.)

Run batch on Windows to copy folder from linuxserver to linuxserver

Setup:
I have two linux server and on both I shared a folder.
Server 1 is for saving and editing files and the second is for the backup.
Then I have a Windows 10 workstation on which I mounted both of the shared folders.
Goal:
I would like to run a batch file on my Windows 10 Workstation with which I can copy a folder (it‘s content) from one linux server to the other.
I've been trying hard since days but it didn't want to work.
Folder structure:
Server 1:
/data/ictproject/[here are the files and folders I want to copy]
The folder "ictproject" is shared.
Server 2:
/backup/[here is the destination]
The folder "backup" is shared.
D:\ on Windows 10
D:\backup[temporary destination]
First try:
#echo off
Xcopy "\\[IP-Adress-Server-1]\data\ictproject" "\\[IP-Adress-Server-2]\backup\ict_%data%" /E
pause 0
Second try:
#echo off
Xcopy "\\[IP-Adress-Server-1]\data\ictproject" "D:\backup\ict_%date%\" /E
Xcopy "D:\backup\ict_%date%\" "\\[IP-Adress-Server-2]\backup\ict_%data%\" /E
pause 0
I also tried the hole thing with copy and plenty other things instead of Xcopy but I didn't try robocopy which actualy is the newer version.(I just got to know that seconds ago)

Batch Copy and run acting strange

I have a batch file that needs to copy my EXE to desktop and run it from there.
Code:
copy client.exe %USERPROFILE%\Desktop
%USERPROFILE%\Desktop\client.exe
What seems to happen is that client.exe is indeed copied to desktop and ran but acts as if it is in the directory of the original client.exe
The problem is that as far as the batch is concerned, the current directory is wherever the batch is execute from.
If you want the current directory to be the desktop, you'd need to explicitly set it
copy client.exe %USERPROFILE%\Desktop
pushd "%USERPROFILE%\Desktop"
client.exe
popd
or
copy client.exe %USERPROFILE%\Desktop
cd "%USERPROFILE%\Desktop"
client.exe
The first temporarily switches the current directory, so it is restored to what it was when run after client.exe terminates; the second makes a permanent switch to the desktop.
If you want start an application and specify where files will be saved (Working Directory), use either
CD /D "%USERPROFILE%\Desktop"
"full_path_to_app\client.exe"
or
START "" /D"%USERPROFILE%\Desktop" "full_path_to_app\client.exe"
Copying the .exe file seems to be a needless action.

forfiles not working in scheduled task

I have created a batch file with the following line:
forfiles /p L:\percepsrvr\SQL /s /m *.bak /d -4 /c "cmd /c del /q #PATH "
This deletes any files older than 3 days and works when I run the batch file.
However, when I try to run this batch file as part of a scheduled task the line of code fails to execute. I think it might be because of the mapped network drive (L:) but don't know for sure.
I have the scheduled task running as myself to make sure it has the same permissions as when I run it manually. The scheduled task is running on a Win2008r2 server box and L:\ is on a Win2003 SP2 server box.
Anyone know what might be keeping this from working properly or how to debug a scheduled task?
TIA
Brian
In case anyone comes across this post I found a solution as follows:
ROBOCOPY "D:\Backup Data\percepsrvr\SQL" "\\belgrade\v$\percepsrvr\SQL"
ROBOCOPY "\\belgrade\v$\percepsrvr\SQL" "\\belgrade\v$\percepsrvr\SQL\Old" *.* /move /minage:10
DEL "\\belgrade\v$\percepsrvr\SQL\Old\*.*" /Q
Basically, move the files to delete to another directory and then delete that directory (which can be done with RoboCopy).

Resources