Use Hobocopy to backup .PST's on system (Using exact path) - windows

Morning All,
We're currently running some software for our users which is failing to copy their PST's on to our servers, it's too intrusive, requires client side software and configuration and its paid for!
I'm used to free/open source software and love command line batch files compared, as I find them easier to automate and also add to scheduled tasks without worrying about users input.
I have found hobocopy which works great! - but only if you list : source folder, dest folder and then file type... my script searches the C:\ drive, finds PST files and lists the full file path. Hobocopy doesn't seem to handle this.
Below is my script:
#echo off
REM ### COPY HOBOCOPY TO WINDOWS DIR #####
if not exist C:\windows\Hobocopy.exe xcopy \\icao-supp-01\support\hobocopy\hobocopy.exe C:\windows
REM ### SCAN SYSTEM FOR LOCAL PST FILES ####
dir *.pst /s /b > C:\temp\pst.txt
REM ### RUN HOBOCOPY TO COPY PST FILES ####
For /f %f in (C:\temp\pst.txt) do hobocopy /y %f P:\
**HERE IS THE OUTPUT OF C:\TEMP\PST.TXT
C:\Jdeane.pst
C:\Games\IGNORE1.pst
C:\Windows\ModemLogs\fake2.pst**
It wont copy the file paths e.g. :
hobocopy /y C:\Jdeane.pst P: wont work. However, hobocopy /y C:\ P:\ *.pst would work.
My goal:
Search the C:\ drive for PST files and then have them backed up on a schedule to the servers.
Thanks in advance!
(PS. Were running Windows 7 x64 and outlook 2010 if it makes a difference, and the users will NOT save their PST's to our servers).

I'm the author of hobocopy. It is written to expect source folder, destination folder, and a file selector. So you're not going to be able to use a full path. That said, you can use the flags that can be found by running "help for" at the command prompt to break apart the path you find into directory and file components. Something like %~nf in your case, I believe.

Related

How to copy a file from a USB drive to C drive in Windows 10 using a batch file?

I have some files in a USB drive which need to be copied to multiple computers. These files contain an executable which will use the other config files.
My issue is, for Windows 10 PCs, while the temp_folder gets created, none of the files get copied.
For windows 7 I was able to create a batch file which copied the files to the local drive and ran the executable using the config files.
The batch file contents were as below :
mkdir C:\temp_installer
copy ".\file_name" "C:\temp_installer"
<rest of the code>
I have tried using xcopy and robocopy, but still see the batch file run and just stop at creating the folder. The same issue isn't observed in Windows 7.
Has someone tried this or can someone tell me what I might be doing wrong?
This would be a better option, we do not need to be concerened about permission issues on the root of C:
#echo off
cd /d "%~dp0"
set "inst_dir=%temp%\temp_installer"
mkdir "%inst_dir%">nul 2>&1
for %%i in (*) do if not "%%i"=="%~nx0" copy /Y "%%i "%inst_dir%"
:# When completed, we can call execute the files from "%inst_dir%"
The for loop is not needed to be honest, I am only doing it to not copy the .bat/.cmd file itself to the folder as there would be no need for it there.
Or even simpler, without having to do all the above, you could just use robocopy
#echo off
cd /d "%~dp0"
robocopy /MIR .\ "%temp%\temp_installer"
Powershell is your friend here, try this:
Copy-Item E:\Document\ C:\Temp\Document\ -R
Works great for me and it even creates destination directory, also Copy-Item has alias cp and copy.
If you running some sort of script, you might have issues with Execution-Policy: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6

CMD/BATCH: Search computer C Drive for a Folder Name and make the address the working location

I basically have over 5 computers(running windows xp,vista,7,8,10, most run win10) i run at home, most but not all computers have different main drive letters(C: or E: or F: etc), and I currently access a folder on these machines manually and I would like to make it more automatic.
I wanted to make a simple batch script that scans the computer(s) for a folder called "Visuals2579211"(this folder name doesn't change on any of my systems, inside this folder is a few cache/txt/tmp files and a program(exe) I made for myself.
So is it possible to search each computer for the folder name:"Visuals2579211" using batch and then make this folders location become the current working directory for further manipulation?
I tried a few scripts and snips of code i found on google and searched around here on stackoverflow as well of coarse, but none of the results are quite what i am after.
I don't mind if the batch script has to create a VBS script or txt file(s) and run them and delete them after with the batch if necessary but I really would like to access my applications folder with a batch file as it would save me a hell of a lot of time. I also plan to have this batch file placed on the Desktop of each machine, So I am searching from the desktop for the Visuals folder.
I know i can make a batch to change CD etc for each machine and specify the current path of each machine but i want the batch to be universal and work on all machines instead of making a batch for each one as these machines drive letters may change over time and i often create and rebuild new machines etc. Any ideas out there?
Test this:
It checks each drive in order and stops at the first drive with the folder.
The ? is to give a wildcard for the for /d /r search command and it can be supplied in different ways.
#echo off
set "folder="
for %%a in (c e f) do if not defined folder (
pushd "%%a:\"
for /d /r %%b in (Visua?s2579211) do set "folder=%%b"
popd
)
if defined folder %comspec% /k pushd "%folder%"

How to move folders in command prompt merging folders with the same name and replacing files with the same name?

I'd like to move my program files and user documents from C:\Windows.old to C:\, completely replacing what's currently in C:. The old and new OSs on my computer are both windows 10, I just had to make a clean install because I couldn't get it to start after a restoration that went wrong. How can I do this operation using the command prompt at windows startup? Is there a command to do this : move, merge folders, replace files with the same name?
Thank you!
First, don't move program files just like that. Programs don't store data only here. Absence of this data might prevent some programs from running, especially licensed ones because they will think it's an attempt of running the executable directly on another computer. A better solution is to reinstall the programs, as it will put everything in the good place to make it is running OK.
Here's the command:
xcopy <Source> <Destination> /s /y
Replace <Source> and <Destination> with their appropriated values. Example:
xcopy C:\Windows.old\Users\David C:\Users\David /s /y
xcopy will ask if it is a file or folder destination. Answer that it is a folder by typing the appropriate letter.
Explanations:The /s command line switch means to copy the entire file and folder structure, while /y means to not ask when overriding files. If you want to look even more geeky, add /f.

Using a networked drive I am trying to access a folder using a variable. I only get the contents of the previous folder.

I have a location on a networked drive that gets a folder with the current date for every file. I am trying to access this location by temporarily mapping the drive (Net Use) and then using the date to fill in the folder name.
When I execute the code it is set to the previous directory. (A DIR listing will bring up the contents of that folder and the rest of the code to move files puts them in that location)
Any ideas?
Thanks
PAUSE
REM This is to move the Export file to the FTP Site.
Set Year_Mo_Da=%date:~10,4%-%date:~4,2%-%date:~7,2%
time /t
net use z: \\Network.com\Validation\2014
REM \%Year_Mo_Da% -- This is the folder name
cd /d z:\%%Year_Mo_Da%%
DIR
Copy Z:\*FileName_*.* Y:\NewLocation\TEST
net use z: /delete
time /t
PAUSE
You're changing directories but then copying from the root after all. #foxidrive removed the backslash but perhaps it wasn't noticed when you made your change?
cd /d z:\%%Year_Mo_Da%%
...you're in the subdirectory
Copy Z:\*FileName_*.* Y:\NewLocation\TEST
...but you copied from the root of Z: after all.
This would work (quotes can't hurt of course but for this example aren't required unless your filename contains spaces):
Copy Z:*FileName_*.* Y:\NewLocation\TEST
BTW I tend to use pushd and popd so I don't have to know the drive letter. Don't know if that helps you or not but you don't have to net use /d either, or care if Z: is in use for something else.
pushd \\Network.com\Validation\2014\%Year_Mo_Da%
Copy *FileName_*.* Y:\NewLocation\TEST
popd
You don't need doubled percents here:
cd /d "z:\%Year_Mo_Da%"
Depending on what you need to do - this may be the next command:
Copy "*FileName_*.*" "Y:\NewLocation\TEST"

Incremetal backups of directories with a batch/shell script

I'm trying to create a script that will automatically backup a complete directory tree. I also want it to work for incremental backups. Basically, it wil work like this:
If file is in both source and destination and they are different, source file will be copied
If file is in both source and destination and they are the same, nothing will be copied
If file is only in the source, source file will be copied
If file is only in the destination, destination file will be deleted.
I'm still new to shell scripting and I'm not sure how I could implement this. Any ideas? Windows batch scripts would be better, but shell scripts that run on Cygwin are also fine.
Take a look at rsync tool - it was designed to minimize traffic during files synchronization.
Also, probably "cp" with "-u" argument will be useful:
-u, --update
copy only when the SOURCE file is newer than the destination file or when the destination file is missing
For windows batch scripting xcopy (native to windows) or robocopy (a free download in windows) both work extremely well.
An example xcopy script (in a .bat file):
#echo off
:: /L = list only.
:: /v=Verify, /y=No prompting /s=subdirs /z=Network mode (supports bad)
:: /i=Tells xcopy dest is folder /f=Display names /d=Copy only changed
echo Backing up projects...
xcopy e:\projects h:\projects /V /Y /S /Z /I /F /D
It will even support orphaned files (if you delete something from your source you no longer need a copy in the backup). Xcopy is typically fine for your needs until you deal with sync between NTFS and Fat32 file systems - the later only has a 2 second resolution and problems with daily savings time so you occasionally run into issues: (a) on time change day you might not get a backup of a changed file - depends on change-regularity of course or you might get a backup of all files even though none have changed (b) because of time resolution some files may backup even though they haven't changed.

Resources