How to copy the file from one windows machine to another windows machine in a particular drive using batch script? - windows

In my windows server, am taking SQL DB backup in C drive. I wants to copy this .bak file to some other client windows machine in a particular drive with the current date using batch script. So that i can schedule this batch script using scheduled task. please help me out.
Can anyone, give a script to run this. thanks

Batch files are always tricky to get just right. First I'd open a command line and see if you can copy between two machines using the following syntax:
copy C:\localfile.bak \\remotemachine\c$\Path\remotefile.bak
(where "remotemachine" is the name of the remote machine and "c$" is the drive you wish to copy to). You can then copy this into a batch file and set up a scheduled task.
As for renaming the file to have the current date and time, I suggest you start with this question as it may involve some effort to get it into a format you want.

Related

Invalid number of parameters in Batch but not in cmd

I am trying to make a scheduled batch file to run with the volume shadow copy service to copy the outlook.pst file from microsoft outlook.
The commands work properly when i enter them in the command panel but when i setup the same code in a batch file it gives me an invalid number of parameters error in during the second line.
You have to use administrator access on cmd and the batch file for it to even work and i am doing that but i have no clue as to why i get an error only in the batch version but not in cmd?
I found this link helpful.
Its where i found the batch file which simplifies the process incase anyone is wondering.
Heres the code :
CALL MountLatestShadowCopy "C:\MyShadow\"
xcopy /y "C:\MyShadow\Users\%USERNAME%\Documents\Outlookove datoteke\*.pst" "\\hyp\backup"
RMDIR "C:\MyShadow"
pause
Anyone have any ideas as to the cause of my problems? Its supposed to simply copy the .pst file to a server for backup which i will run on a regular schedule.
Outlook is usually the first thing people open when they turn on their computers so i have to use volume shadow copy otherwise getting a copy might be hard on certain computers.
Thanks for the help in advance!

File Move Scheduled Tasks not running bat file

I know this question might have been asked in other ways, but all the things I have read and tried had not yet fixed my problem, so I am hoping to get some help here with context to my issue.
The problem:
I need to move files from a local drive to a network drive (the network drive is a SharePoint mapped library) on my server in Windows Azure (don't think the azure part matters, but it provides context).
My thought was to schedule a task that will run a bat file to move the files I need moved and do so frequently (every 5 to 10 minutes). The batch file I have created does what I need it to when I manually run the batch file but not when the task runs it.
Here is the batch file:
echo Write log file > LogStart.txt
C:\Windows\System32\robocopy.exe "\\PCICSWKS001\D$\ToBeMoved" "V:" /s /e /MOV /r:0 /W:0
echo Write log file > LogEnd.txt
You can see that it writes a log file before and after running robocopy.exe.
When the task runs it does write both of these log files so I know that the batch file is at least running.
You can also see that I have tried using the UNC path for the drive in the source, that is because I was reading that the task scheduler might not be able to pick up properly on the drive letters. When I put the machine name in for the destination and run the batch file myself or with the scheduler it errors.
Here is the action taken by the task:
Here is the task general tab
Any assistance would be much appreciated.
I had that same error with Robocopy after a few times of running it:
ERROR 3 (0x00000003) Getting File System Type of Destination
I think it has to do with how robocopy scans the destination when it has a fair amount of files on it. It worked fine when I started the copy job and the Azure destination was empty.
Anyway, I think you should try to use the AzCopy command as that should be less error prone and faster since it was designed for this kind of thing. It's command line switches are similar to robocopy so it should feel pretty familiar.

Using vssadmin through a batch command or powershell

I need to access a file that is open by another process all the time. The best way would be for me to use Windows Shadow Copy to create another copy of the file and then use the copied file.
Does anyone know how to use vssadmin to create a backup and extract a specific file through a batch command or power shell? I would like to automate the process to run every night.
Jason
Here is a page with examples on how to create snapshots from a command line with vssadmin:
http://blogs.msdn.com/b/adioltean/archive/2004/12/14/301868.aspx

windows batch file to copy a file from a server to local

I would like to write a little code that copy on a local pc a file from another (a server).
Which Windows batch file function I can use to write this little batch file program, (FTP maybe?)
And also to visualize a message on my pc (the local pc)
thanks for all
Just use wget.
It can be called from your batch file and will download from HTTP and FTP.
Write SHUTDOWN -i in a note pad then save to desktop and name it anything but it must have .bat at the end and then click save and u can shutdown any computer in you server.

Scheduled Task: Directory cleanup using windows batch script

I have a shared disk that I would like to clean up once per week using a scheduled task of some sort. I would like to use a batch script so that the system admins can easily modify it or reuse it on other directories when needed.
The directory has files with multiple file extensions but the ones that need to be deleted end in .bkf and must be over 2 weeks old.
Does anyone have a batch script solution for this windows server (not sure which version)?
If you have PowerShell (or can install it), check out this link: http://thepowershellguy.com/blogs/posh/archive/2007/12/13/hey-powershell-guy-how-can-i-delete-files-that-are-a-specified-number-of-hours-old.aspx
Take a look at this page - scheduling tasks from command line
It shows you hot to create scheduled tasks from the command line. You might be able to use this in combination with other dos commands to get your result.
The only thing that needs to be in the batch file is
#echo off
cls
del C:\some\directory\*.bkf
And the delete path can also be sent to this batch script as an argument so that the directory is changeable.
I ended up just writing an EXE that accepts parameters and scheduling that. Unfortunately the other solutions didn't have the flexibility needed.
have you looked into forfiles.exe?
http://blog.stevienova.com/2007/02/27/forfiles-delete-files-older-than-x-amount-of-days/

Resources