Run batch on Windows to copy folder from linuxserver to linuxserver - batch-file

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)

Related

Writing a script to look for a folder and run a batch file in it

I have a really messy program in my environment that basically has a jump client on over 7000 machines in my environment. When I upgrade the appliance that the jump client talks to it starts an in place upgrade but if there are computers off or off the network obviously the upgrade times out. Problem is, I cant mass deploy the updated jump client because the previous version has to be uninstalled first.
WMIC uninstaller doesn't work, msiexec uninstaller doesn't work. There is a batch file built into the program stored at %ProgramData%\ClientNameRandomNumbers. Problem is, you can also install a dissolvable client in the moment if needed and everytime the dissolvable client installs, it doesn't clean up after itself. So you have random folders that may or may not be the one that contains the uninstall.bat batch file that I need to run. I wanted to write a script to mass deploy that will start that batch file on each computer but I am having problems.
Basically I want it to search for the folder with a wild card, if it finds it CD to that directory and then try to run the uninstall, if it can't find the uninstall, continue through to deleting the folder as it is an old shell folder. And then go back and look for more folders until it can't find anymore and then go to exit.
This is what I have:
:START
cd %programdata%\bomgar-scc* || IF ERRORLEVEL not = 0 GOTO END
start uninstall.bat /Wait || cd c:\programdata &&
rd C:\programdata\bomgar-scc*
GOTO START
pause
:END
EXIT
Any suggestions?
I think I am understanding your requirements but maybe not. I have commented the code to let you know what it is doing.
#echo off
REM For command will attempt to find all folders
REM that start with bomgar-scc in the programdata folder
for /d %%G IN ("%programdata%\bomgar-scc*") do (
REM If it finds a folder check if an uninstall.bat
REM exists and run the batch file if it does exist.
IF EXIST "%%~G\uninstall.bat" CALL "%%~G\uninstall.bat"
REM Remove the directory found
rd "%%~G"
)
Create a Jump client MSI installer. Run the following command to uninstall it.
msiexec.exe /x "\%networkpath%\bomgar-scc-win64.msi" /quiet

how to restore with batch file in windows

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

Relative path doesn't work on shared directory

xcopy "D:\CCStudio\rtos" panasonic /s /e
The folder panasonic and the bat file are on the same level in the directory structure, although on another machine I have access to.
When I use the bat script on my PC everything works fine. But when I put the bat script into the remote shared folder, it doesn't work as expected. The problem seems not to be the source, instead the destination address is the key in the problem. When I replace `pansonic' whit its absolute address, the script works.
So why should I specify absolute path for destination? Recall that the destination is external path. It is shared folder on another windows machine.
I currently run a bat from a shared drive to copy to another shared drive. This is what I use to get it working fine. Adjust as needed.
cd /d %~dp0
xcopy /s "D:\CCStudio\rtos" "panasonic\" /E
cd /d %~dp0 will change the directory to what ever the batch file is in allowing you to use relative paths. This script will copy the files in rtos to panasonic. Folder path will look something like this X:\Shared\Network\panasonic\RtosFiles.ini assuming RtosFiles.ini was in D:\CCStudio\rtos and the batch was run in X:\Shared\Network\

XCOPY batch file

I’m looking to create a batch file that transfers all my music from my external drive to my Samsung note 3. The idea is just to click the batch file and for it to update any song on my external on my phone.
Heres what I’ve got
XCOPY "E:\Music\*.*" "Computer\SAMSUNG-SM-N900A\Phone\Music\" /e /c /r /k /y /v
The problem I see is that it’s creating a folder on my desktop with that path, the directory on my desktop being computer with the following subfolders.
I’m not sure why it won’t recognize the path, any ideas?
You can't directly copy files from windows to an android device, its a different file system. You can probably do it manually with this program:
https://android-file-manager.en.softonic.com/

ClickOnce Deployment with a Database as a Prerequisite

I have a Winforms application that I want to publish using ClickOnce. This application comes with an initial database, which must be installed once on a per-machine basis. After much ado, I have landed on the idea of using a custom pre-requisite to install the .sdf file. I have used Bootstrapper Manifest Generator (BMG) to create a package for the .cmd file I want to run, and I have included the .sdf file as an "additional file."
My expectation was that the two files would end up in the same directory, and I would be able to copy the .sdf file to the place where I want it (They do end up in the same directory.) The pre-requisite shows up in Visual Studio just fine. It get's deployed to the client system just fine, and the setup program kicks off the prerequisite just fine.
The only problem is that the current working directory that the .cmd file is executing is C:\Documents and Settings\\Desktop!
Neither of the two files (.cmd or .sdf) are located there - they were downloaded elsewhere, e.g., "C:\Documents and Settings\drogers\Local Settings\Temp\VSD5A.tmp". So, although I know where to xcopy to, I have no idea where to xcopy from.
How can I resolve this?
Here is the .cmd file:
REM Modify this file to reflect your manufacturer name [FHCRC] and product name [ClickOnceSharedDataDemo].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\FHCRC" mkdir "%TargetBase%\FHCRC"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" mkdir "%TargetBase%\FHCRC\ClickOnceSharedDataDemo"
CACLS "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" /E /T /C /G "Users":C
xcopy shareddata.sdf "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" PAUSE
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" exit /B -1
:EXIT
PAUSE
exit /B 0
Thanks,
David
Well, I am not altogether happy with this solution, but it works. I now have two prerequisites. the first is just the command file which runs the CACLS commands to set permissions. It is basically a shortened version of the above:
REM Modify this file to reflect your manufacturer name [Manufacturer] and product name [ProductName].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\Manufacturer\ProductName\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\Manufacturer" mkdir "%TargetBase%\Manufacturer"
if not exist "%TargetBase%\Manufacturer\ProductName" mkdir "%TargetBase%\Manufacturer\ProductName"
CACLS "%TargetBase%\Manufacturer\ProductName" /E /T /C /G "Users":C
:EXIT
ECHO exit /B 0
The second prerequisite is an "all users = true" setup project which has a custom folder located at default location:
"[CommonAppDataFolder][Manufacturer][ProductName]".
Into this folder I put the sdf file.
Finally, I used Bootstrapper Manifest Generator to make packages for both, making the second dependent on the first. I copied the packages to the appropriate VS2010 directory, included them as prerequisites, and published.
I now have per-machine .sdf files published to both WinXP and Win7. Why does this have to be so difficult!?!?
I'm still looking for less complicated solutions, that will install to both Windows 7 and Windows XP.
Did you try MSDeploy? It is able to fulfil all your needs.
Cheers!
You could just include the .sdf file with the ClickOnce application, then have your program copy it to somewhere else the first time it runs. I never recommend keeping the data in the CLickOnce cache anyway, it's safer to handle it yourself. See if this article helps at all:
http://robindotnet.wordpress.com/2009/08/19/where-do-i-put-my-data-to-keep-it-safe-from-clickonce-updates/

Resources