Robocopy

Hi,

Can you please help me convert this batch code into procedure?

@echo on

robocopy “%userprofile%\documents” “\scv-s-srv01\Backups%username%\documents” . /COPYALL /XO /XF “default.rdp” “Desktop.ini” /XD “My Pictures” “My Videos” “My Music” /B /E /R:5 /W:3

robocopy “%userprofile%\desktop” “\scv-s-srv01\Backups%username%\desktop” . /COPYALL /XO /XF “default.rdp” “Desktop.ini” /B /E /R:5 /W:3

What I need here is to backup the documents and desktop of the logged on users.

Thank you,

Hi @alfie013 ,

We will analyze and update the script request shortly.

Thank you.

@Preethi,

Thanks. Looking forward to it.

Regards,

Check out UrBackup. Its a free backup software that will do this for your. Much better than running scripts !!

@dittoit ,

Do i need to install this on every machine? If yes, then it will not work for us because what we need is to schedule the procedure every week without the user’s knowledge.

Regards,

Its a server and client. It is all controlled from a web interface. No user input required.

Hi @alfie013

Please use this script to backup the documents and desktop of the logged on users.

NOTE:Please run the script as logged in user

Edit the following parameters as per your need :
server_user_name=r"administrator" #provide the username of the destination server
server_password=r"Password" #provide the password of the destination server
path1=r"\WIN-6OU2UM9BPFN\backup" #provide the destination network share path folder

you can also refer the attached JSON file



server_user_name=r"administrator" #provide the username of the destination server
server_password=r"password" #provide the password of the destination server
path1=r"\\WIN-6OU2UM9BPFN\backup" #provide the destination network share path folder


import os
import sys
import platform
import subprocess
import ctypes
import getpass
from subprocess import PIPE, Popen
username="%userprofile%"
user=getpass.getuser()
BAT=r'''
@echo off

robocopy "%s\documents" "%s\%s\documents" *.* /DCOPY:T /XO /XF "default.rdp" "Desktop.ini" /XD "My Pictures" "My Videos" "My Music"  /E /R:5 /W:3

robocopy "%s\desktop" "%s\%s\desktop" *.* /DCOPY:T /XO /XF "default.rdp" "Desktop.ini"  /E /R:5 /W:3

'''%(username,path1,user,username,path1,user)

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)



path=os.environ['programdata']+"\Sample.bat"
with open(path,"w") as f:
    f.write(BAT)

with disable_file_system_redirection():
    print "Excuting Bat File"
    cmds= 'NET USE "'+path1+'" /USER:'+server_user_name+'  "'+server_password+'"'
    process=os.popen(cmds).read()
    process1 = subprocess.Popen([path],stdout=subprocess.PIPE)
    stdout = process1.communicate()[0]
    print "---------------------------"
    print stdout
    print"Desktop and Documents are copied to the backup folder"

if os.path.exists(path):
    try:
        os.remove(path)
    except:
        pass



20180129-Convert-batch-code-into-procedure.json (2.73 KB)