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.
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