How to backup to removable storage: RoboCopy and PowerShell

PowerShell script exchange

How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby tim5700 » Sat May 16, 2009 3:24 pm 1 person likes this post

I was asked to post on this after tweeting it last night.

A lot of my clients are used to rotating their backup media. Most of my clients prefer to keep copies of their backups off site for DR purposes. The problem I've into with rotating backup media is that Veeam may want to remove files etc.

To simplify the process, we are using Veeam to backup to a hard drive on the computer running Veeam all the time. Then have another set of disks that will rotated periodically.

Use a batch file with robocopy to mirror your permanent backup drive to the rotated drives for off site storage. As a result you always have a few backups ready and waiting on the Veeam server, but you also have off site backups in case of DR.

Something I quickly found out as I sometimes have non-technical folk trained to swap the removable drives is that they will do it regardless of whether the robocopy job is complete. Solution? Send them an email when it is safe to swap the drives. The result is a batch file and a powershell script. Install robocopy and powershell on your Veeam server. Run the batch file after your backup runs. Here's the script snippets.

Post_Backup_Copy.bat:

robocopy e:\ f:\ /MIR /r:3 /w:1

powershell.exe c:\scripts\RoboCopyEmailAlert.ps1

That's it for the batch file. It runs a robocopy and mirrors everything from drive E:\ (the permanent drive) to drive F:\ (the rotated drives)

It then runs the powershell script to send an alert when the process is complete.

RoboCopyEmailAlert.ps1:

## Define the variables for smtp server, from address, to address, subject and message body

$emailFrom = "administrator@domain.com"

$emailTo = "backupusers@domain.com"

$subject = "Backup Mirroring Operation Complete"

$body = "The robocopy hard drive mirroring operation is complete, it is now safe to change the backup hard drives."

$smtpServer = "x.x.x.x"


## Initiate sending a message to the IT group.


$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$smtp.Send($emailFrom, $emailTo, $subject, $body)


That's it, when the copy is complete an email will go out. I usually, send it to a distro group so that I get it and the responsible people get it.
tim5700
Enthusiast
 
Posts: 30
Liked: 1 time
Joined: Fri Apr 17, 2009 11:31 am

Re: Veeam and removable storage - use RoboCopy and PowerShell.

Veeam Logoby Gostev » Sat May 16, 2009 3:46 pm

Thank you - stickied!
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby johnny@datafant.se » Mon Jun 01, 2009 10:50 am

Hello,

thanks for this valuable information.

Got one problem though, maybe it is in my environment only:

I have tried putting the email script created with Powershell both within the same and a separate BAT file as the RoboCopy command.
It only runs the Robocopy command but no email is received.

When I double click the BAT file, I receive the email.
Also when scheduling the BAT file with Windows Scheduler, I receive the Powershell created email.
But not when attaching this RoboCopy BAT file to the post command field in VB as described by you.

Any ideas ?

Regards,

Johnny Lundgren
johnny@datafant.se
Enthusiast
 
Posts: 58
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby johnny@datafant.se » Tue Jun 02, 2009 9:58 am

Anton,

concerning my Powershell email problem above; what credentials is used by VB with the post job command possibility ?
Since both the RoboCopy command and the Powershell script reside in the same BAT file, both should work but unfortunately only the RoboCopy command works.

And as I wrote, when scheduling the Powershell command with Windows Scheduler on the same machine(tested with both domain and local credentials) it works fine and I cannot understand why.


Regards,
Johnny
johnny@datafant.se
Enthusiast
 
Posts: 58
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: How to backup to removeable storage: RoboCopy and PowerShell

Veeam Logoby Gostev » Tue Jun 02, 2009 11:40 am

Johnny, actually it was team who posted solution, I hope he can comment on your issue. Post job command is started by Veeam Backup service under the same credentials that it runs.

Now, while I am definitely not a big PowerShell guy, I think I remember from early PS days that it has some security settings that define how it can be started (interactive only, or from other apps/services). May be this is what causing your issue?
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: How to backup to removeable storage: RoboCopy and PowerShell

Veeam Logoby tim5700 » Mon Jun 15, 2009 2:55 pm

Hi Johnny,

Sorry for the late response on this.

This could be an issue of the SMTP server not relaying the message. If you are using MS Exchange, there are settings for SMTP relay that can be configured to require authentication for the message to be sent through the Exchange server's SMTP service.

You can specify the service you are using to run Veeam, or you can configure Exchange to accept SMTP from the IP address of your Veeam server.

Thanks,

T
tim5700
Enthusiast
 
Posts: 30
Liked: 1 time
Joined: Fri Apr 17, 2009 11:31 am

Re: How to backup to removeable storage: RoboCopy and PowerShell

Veeam Logoby johnny@datafant.se » Mon Jun 29, 2009 6:51 am

Hello again,

I still have problems with the

Powershell Email Script

although using the Domain Admin account on the Veeam Service (VB Email always works).
When using the local Administrator account it works fine.
It is correct that I am using an Exchange 2003 Server as the SMTP server and this server relays email correctly when using the Windows Scheduler on the same Veeam Backup computer (both local Admin and domain Admin accounts).
In Windows Scheduled Task I can specifically set the account I want to use, I cannot do this in the Veeam Backup interface.
Powershell executionpolicy is set to unrestricted.

There should be a possiblity to run scheduled postjob scripts without having to backup a vm, just for quick testing.
Can I do this in VB in some way ?

Finally once again, what is the difference between running the VB postscipts with the Domain Admin account on the VB service, which does NOT work, compared to running the Windows Scheduled Task with differents Admin accounts (Local or domain) which DOES work ? On the same machine ?

Regards,

Johnny
johnny@datafant.se
Enthusiast
 
Posts: 58
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby Gostev » Mon Jun 29, 2009 10:50 am

Johnny, does your test work when you use VB service account to run Windows Scheduled Task?
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby johnny@datafant.se » Mon Jun 29, 2009 11:07 am

Yes, I am using the domain admin everywhere when testing.
johnny@datafant.se
Enthusiast
 
Posts: 58
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby Gostev » Mon Jun 29, 2009 1:12 pm

Johnny, it looks like you misunderstood my question. Can you look up what service account is being used by Veeam Backup service, and perform Windows Scheduled Task test using that account, instead of another domain admin account?

We have seen it many times when the fact that account is domain admin did not really help, and there were still some "access denied" errors due to some local settings. What you can try to do is use services.msc applet to change the Veeam Backup service account to the one with which the script surely works when scheduled using Windows Scheduler.
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby johnny@datafant.se » Mon Jun 29, 2009 4:24 pm

Anton,

Sorry for not being very clear.

When I use domain admin as VB service account - PS email script does not work.
When I use domain admin as Windows Scheduled Task acount - PS email script works.

When I use local admin as VB service account - PS email script works.
When I use local admin as Windows Scheduled Task account - PS email script works.

Note, the Veeam Backup job SMTP email via same Exchange server works all the time.

You may think this is a minor problem and not even a Veeam concern,
but I need this function and would like to be able to easlily test scheduled VB job and postscript email without having to backup a whole vm.


/Johnny
johnny@datafant.se
Enthusiast
 
Posts: 58
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby Gostev » Mon Jun 29, 2009 5:22 pm

Johnny, in this way this issue may looks be related to Veeam Backup, but I wonder why it works fine for original poster. Anyway, it would be best to let our developers invetigate - can you please open support case and send us all logs as well and most importantly your script.
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby johnny@datafant.se » Mon Jul 06, 2009 7:39 am

Hello,

I just want to clear out my PowerShell email script problems once and for all:

This problem is NOT Veeam Backup related.

In the end, all I needed to do was to add the VB service account being used ( in my case, the Domain Admin account), to the local Administrators group.
So, even if the Domain Admin account reside in the Domain Admin group, which in turn reside in the local Administrators group, this is not enough to make it work.

I had other problems with my Robocopy/Powershell script which resulted in added confusion, but that is related to errorlevel codes not working correctly with Robocopy version XP026. And that is an issue I have to deal with Microsoft.

In any case, thanks for taking my problem seriously.

Regards,

Johnny Lundgren
johnny@datafant.se
Enthusiast
 
Posts: 58
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby Gostev » Mon Jul 06, 2009 3:45 pm

Hello Johnny, I am glad that it works now - and thank you for updating the topic with resolution.
Gostev
Veeam Software
 
Posts: 21396
Liked: 2350 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: How to backup to removable storage: RoboCopy and PowerShell

Veeam Logoby Rich » Mon Jan 11, 2010 3:43 pm

Thanks for the info - much appreciated. We now have a similar backup strategy in place whereby robocopy mirrors onsite Veeam backups to a pair of rotated 2Tb USB drives for offsite DR purposes. Works nicely.

I've just noticed the 'File Copy' function in Veeam. Just wondering - could this be used as an alternative to robocopy for mirroring of Veeam backups to USB drives?
Rich
Novice
 
Posts: 6
Liked: never
Joined: Fri Nov 27, 2009 9:37 am
Full Name: Richard Main

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests