How to sync 2 directory content on 2 different computer during file change only - windows

Lets say I have PC A(with folder C:\PCA) and PC B (with folder C:\PCB)
first i do a WNetAddConnection2 to map PCB folder on PC A with S drive letter
followed by a copy command cmd.exe /C copy S:*.* C:\PCA\ /Y
but this will be just copy all files in PCB to PCA everytime i call it
I'm looking for a way to Sync PCA and PCB (One way is ok) and the process should copy only files with changes(to save bandwidth).

This type of action could be performed on Linux with a tool called rsync
Maybe try take a look at this answer:
https://superuser.com/questions/69514/windows-alternative-to-rsync
for some Windows alternatives.

Related

Copy File to Another Server Using Batch File [duplicate]

I have a bat file copying files from current machine to mapped network drive (one line, xcopy command).
It works when I RDP to server. However, when I run as a scheduled task, and configure it to run under the same user I'm logged in, it doesn't work and give error 0x4.
Is there a way I can achieve this?
I also try dsynchronize and it works when I click synchronized. When I run it as service same issue.
I was able to figure it out. Following batch files works under scheduler, even as local system account:
net use m: \\server\share /U:server\user password
xcopy C:\source m: /E /Y
It maps a network drive every time and then copy to that drive
It's possible to copy files to a UNC path without mapping as a network drive.
Just try to set the UNC path in quotes.
copy * "\\server\share"
Without the quotes, i got a "syntax error" running on Windows7 command line.
I had similar issue where I wanted to copy file(s) from a server to hundreds of other servers without mapping a remote drive to my local PC. I didn't have enough drive letters to map hundreds of remote machines to my local PC! I couldn't just map the remote drive and copy.
I thought I could use copy, xcopy, or robocopy, and specify my creds to the copy command. But none of the copy commands had any options to provide credentials to remote system.
Thanks to the post above, I was able to create a small batch file where I just loop through my hosts, and keep re-using just one drive mapping for all my hosts.
Here is my batch file...
echo #off
for /F %%j in (pchostslist1.txt) do (
net use z:\\%%j\c$ /user:domain\myusername mypassword
mkdir \\%%j\c$\tmp\mynewdir
xcopy c:\anyfile.txt \\%%j\c$\tmp\mynewdir
net use z: /delete
)
I had a similar issue and instead of using net use I simply needed to store the password as part of the scheduled task. You'll notice that it says it only has access to local resources if it's ticked.
Who maps the network drive? And are you using the mapped name, instead of the underlying UNC native path? Because it sounds like the mapped drive is setup in your login script, which doesn't run if you're not logged in. So, in a scheduled task, you do have the correct credentials for the UNC path, but no mapped drive letter.

Is there a way in Windows 10 to create a virtual link from an UNEXISTING file to an existing one?

I'm using Windows 10 on a device that has only one SSD formatted with NFTS, the drive letter is C:\
I have an application that looks for a file located in D:\afolder\needed.file (I can't change this)
Is there a way to put the file needed.file in C:\ and create a virtual link so that this application thinks is working on D:\afolder\needed.file but transparently the OS is redirecting it to the file located in C: ?
I tried with the command
mklink /H D:\afolder\needed.file C:\needed.file
but I receive the error
Local NTFS volumes are required to complete the operation.
Maybe it is because the drive D: doesn't exist at all on the device?
Is there a way to make it work?
NOTE: The SSD of the device is formatted with NTFS and I run the command mklink with admin privileges

How do I autorun my Python script when I plug in my USB device?

I want to execute my Python script (at root, "autorun.pyw") whenever my USB device is plugged into a port.
I don't want to install any software. I am using Windows 10, and I have tried using an autorun.inf file.
Help would be greatly appreciated.
First Step: Install software
Restore the auto-run function To restore the "auto-run" function, the first thing we will need to do is download APO USB Autorun, a small free program that monitors the USB devices connected to the computer. Once installed, whenever you connect a USB storage device, such as a USB stick, it will check if there is an autorun.inf file inside the device and will run the configured program.
Second Step: Create autorun.inf
Create the autorun.inf file To automatically run a program from the flash drive, it needs to have two things, the program you want to run automatically and a script file that points to the program on the flash drive. Copy the executable file of the program you want to run to the pendrive. Then open the notepad, copy the text below and paste it into the notepad window to create the autorun script. [autorun]; Open = MEUAPP.exe ShellExecute = MEUAPP.exe UseAutoPlay = 1 Once you have pasted the text in the notepad, replace the text “MEUAPP” with the name of the program file you copied to the USB stick that will run automatically, as shown in the example below. Then, save the file to the USB stick named autorun.inf. Important: Make sure to select the option “All files (*. *)” In the “Type” field so that the file is saved with an INF extension and not a TXT extension. The flash drive should now contain the program's executable file and the autorun.inf file you just created. You can use the USB stick to place other files, but be sure to keep both files. Note: If the portable program has multiple files, you can copy its folder to the USB stick, just make sure to enter the path in the ShellExecute field. Ex: ShellExecute = PASTADOAPP \ MEUAPP.exe.
Final Step: Configure and run automatically
Run the program automatically: Once this is done, whenever you connect the pendrive to the computer, APO USB Autorun will detect your autorun.inf file inside the pendrive and will automatically run the program you have configured. Finally, note that you will need to install APO USB Autorun on all computers where you want to use autorun. Still, it can still be useful if you work on the same computers.

Can't copy files to UNC Destinations if BAT file is called via scheduled task

I have a bat file copying files from current machine to mapped network drive (one line, xcopy command).
It works when I RDP to server. However, when I run as a scheduled task, and configure it to run under the same user I'm logged in, it doesn't work and give error 0x4.
Is there a way I can achieve this?
I also try dsynchronize and it works when I click synchronized. When I run it as service same issue.
I was able to figure it out. Following batch files works under scheduler, even as local system account:
net use m: \\server\share /U:server\user password
xcopy C:\source m: /E /Y
It maps a network drive every time and then copy to that drive
It's possible to copy files to a UNC path without mapping as a network drive.
Just try to set the UNC path in quotes.
copy * "\\server\share"
Without the quotes, i got a "syntax error" running on Windows7 command line.
I had similar issue where I wanted to copy file(s) from a server to hundreds of other servers without mapping a remote drive to my local PC. I didn't have enough drive letters to map hundreds of remote machines to my local PC! I couldn't just map the remote drive and copy.
I thought I could use copy, xcopy, or robocopy, and specify my creds to the copy command. But none of the copy commands had any options to provide credentials to remote system.
Thanks to the post above, I was able to create a small batch file where I just loop through my hosts, and keep re-using just one drive mapping for all my hosts.
Here is my batch file...
echo #off
for /F %%j in (pchostslist1.txt) do (
net use z:\\%%j\c$ /user:domain\myusername mypassword
mkdir \\%%j\c$\tmp\mynewdir
xcopy c:\anyfile.txt \\%%j\c$\tmp\mynewdir
net use z: /delete
)
I had a similar issue and instead of using net use I simply needed to store the password as part of the scheduled task. You'll notice that it says it only has access to local resources if it's ticked.
Who maps the network drive? And are you using the mapped name, instead of the underlying UNC native path? Because it sounds like the mapped drive is setup in your login script, which doesn't run if you're not logged in. So, in a scheduled task, you do have the correct credentials for the UNC path, but no mapped drive letter.

Can't copy big DB files using "copy", "robocopy" or even "eseutil"

I am having a problem copying large DB files (~100GB) in an automated script I am trying to write for a Windows Server. I have tried using "copy", "robocopy", and even "eseutil".
My script is running on a Windows 2008 Server (destination of the file) and is pulling from a Windows 2003 Server (source of the file).
I have already tried changing the IRPStackSize registry setting, as well as both of the ones in the HKLM/SYSTEM/CurrentControlSet/Control/SessionManager/MemoryManagement hive. This was all done on the 2008 server and rebooted with no effect. Does anyone have a good workaround?
Copy and Robocopy both give me this:
Not enough server storage is available to process this command.
Eseutil.exe gives me this:
H:\TempSQLBackups>eseutil /y \\SRC_SERVER\SQL_BACKUPS\BIG_DB.BAK /d H:\TempSQLBackups\BIG_DB.bak
Extensible Storage Engine Utilities for Microsoft(R) Exchange Server
Version 08.01
Copyright (C) Microsoft Corporation. All Rights Reserved.
Initiating COPY FILE mode...
Source File: \\SRC_SERVER\SQL_BACKUPS\BIG_DB.BAK
Destination File: H:\TempSQLBackups\BIG_DB.bak
Copy Progress (% complete)
0 10 20 30 40 50 60 70 80 90 100
|----|----|----|----|----|----|----|----|----|----|
........FAILURE: ReadFile: The specified network name is no longer available.
Operation terminated unsuccessfully after 11336.16 seconds.
H:\TempSQLBackups>
I figured out how to fix this!
Use a LINUX machine to samba mount the source and destination directories/drives and copy them via the network. Personally, I use rsync since it will recreate the directory structure and only copy files that aren't there or are different. Thus, you can stop and/or restart at anytime without losing your progress.
I can't believe we're still paying Microsoft for this trash of an OS. I had similar problems and there seems to be no fix other than this one. Its a little slow but not nearly as slow as doing on natively since it will fail EVERY TIME.
At one point I thought robocopy would surely do it using the /IPG:xx option (InterPacketGap in milliseconds). Nope. It just PROLONGS the stack overflow and remote console lockout. I thought, maybe, Microsoft got it right with this OS. So much for Win2K8 being solid. Ugh! Windoze is for workstations. For servers you need a server OS not tinkertoy code.
Use the XCOPY with the /J option to avoid network failures of large files. This will ONLY works in 2008 R2 and Windows 7 though. This solved my timeout issue.
Please check.
Have you tried to copy the files with the old fasion way of drag and drop?
I would do this once, to make sure its not your network failing. Make sure that works, and then try look at other solutions.
1) Make sure your destination drive, is NTFS and NOT Fat32.
2) Check when its failing to copy, is it always at the same point? ( IE if it always failing after 2gb )
Have you tried xcopy? It works better for large files and recursive copy. doc
Also, from my own experience working with network drives and command line is a pain and buggy. It is also a good idea to map the network drive and use drive letter such as z:\
xcopy /K /R /E /I /S /C /H /G /X /Y s:\*.* t:\
/K Copies attributes. Normal Xcopy will reset read-only attributes.
/R Overwrites read-only files.
/E Copies directories and subdirectories, including empty ones.
/I If destination does not exist and copying more than one file, assumes that destination must be a directory.
/S Copies directories and subdirectories except empty ones.
/C Continues copying even if errors occur.
/H Copies hidden and system files also.
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
/G Allows the copying of encrypted files to destination that does not support encryption.
/X Copies file audit settings (implies /O).
The format for the second part of eseutil should be:
/d\\server\folder\filename
Notice there is no space after the /d

Resources