(SOLVED) Running batch in Real Time Sync in MacOS for AFP

Get help for specific problems
Posts: 15
Joined: 20 Sep 2017

SipriusPT

Hello,

I have been using batch files in Real Time Sync running in startup in Windows without problem, but I am trying to do the same in MacOS but I cannot find a way to do it.

In MacOS I can only 'open' every batch file with FreeFileSync, if I try directly with RealTimeSync, I cannot open it.

So I cannot manage a way to execute those batchs in RealTimeSync in startup.

Here are some info about those batchs:
http://prntscr.com/h4bgbf

I have tried with a python script as a last resort to launch that batch file at startup but cannot find a way to stop it in case of FreeFileSync launch popups, it simply continue to run. (If needed I can paste the code here)

Thanks!
Posts: 15
Joined: 20 Sep 2017

SipriusPT

I have not meationed but Real Time Sync doesnt work in my MacOS 10.11.6 (El Capitan). I have tried to launch it with FreeFileSync batch that was working well, but doesnt sync, and doesnt give me any error.

Also I have tried to get a batch file RTS (didnt knew that there was that feature) and still no sucess.

I have followed this thread:
viewtopic.php?t=290
Posts: 15
Joined: 20 Sep 2017

SipriusPT

So I have made a python script to interact with RTS batchs to be able to use those under AFP.

Here is a script if anyone here wants to share and backup automatically without problems under AFP on MacOS to save Extended Attributes of files, I have fully tested it against network cuts (also under low signal of wireless) since I will have to install it in several MacOS machines and also against huge data transfer. In case of a failure the user will be seeing a native macos warning window.

Requirements:
- Python 3.7

Optional:
- LaunchControl (to launch python script on startup as a plist on user agent to be able to see RTS icon GUI when working, you can use other ways to accomplish this)

Here is the script:
import os
import sys
import subprocess
import time
import re

####EDIT HERE####
ffs_batch_folder_path = '<.../RTS_Config/>'
ffs_batch_file = '<BatchRun_.ffs_batch>'
nas_folder_path = '<...>'
u = '<user>'
p = '<pass>'
ipnas = '<remote ip>'
#################

#Quick info#
#mount_afp output cannot be recorded through subprocess
#re.search(A in var) true - is not None
#re.search(A in var) false - is None

sleep_period = 60 #in seconds
first_launch_sleep_period = 30 #in seconds

def run_ffs_batch():
    #give some time to connect remote folder where it will sync
    time.sleep(first_launch_sleep_period)
    local_mount_folder = os.path.join('/Volumes/'+nas_folder_path)
    #auto connect to remote folder
    if (os.path.exists('/Volumes/%s' %nas_folder_path) is False):
        try:
            os.mkdir(local_mount_folder)
        except OSError as e:
            print('%s' %e)
    try:
        mount_afp_ps = subprocess.Popen('mount_afp -i afp://%s:%s@%s/%s %s' %(u,p,ipnas,nas_folder_path,local_mount_folder), shell=True, stdout=subprocess.PIPE)
        read_mount_afp_ps = mount_afp_ps.stdout.read().decode('utf-8')
        mount_afp_ps.stdout.close()
        mount_afp_ps.wait()
        ping_ps = subprocess.Popen('ping -c 3 -m 3 -i 1 %s' %ipnas, shell=True, stdout=subprocess.PIPE)
        read_ping_ps = ping_ps.stdout.read().decode('utf-8')
        ping_ps.stdout.close()
        ping_ps.wait()
        print ('read_ping_ps:\n%s' %read_ping_ps)
        abc = re.search('100.0% packet loss',read_ping_ps)
        print ('%s' %abc)
        if re.search('100.0% packet loss',read_ping_ps) is None:
            print ('Remote folder is mounted!')
        else:
            print ('Remote folder is NOT mounted!')
    except OSError as e:
        print('%s' %e)
    #starts periodic function
    while(1):
        ping_ps = subprocess.Popen('ping -c 3 -m 3 -i 1 %s' %ipnas, shell=True, stdout=subprocess.PIPE)
        read_ping_ps = ping_ps.stdout.read().decode('utf-8')
        ping_ps.stdout.close()
        ping_ps.wait()
        ls_ps = subprocess.Popen('ls %s' %local_mount_folder, shell=True, stdout=subprocess.PIPE)
        read_ls_ps = ls_ps.stdout.read().decode('utf-8')
        ls_ps.stdout.close()
        ls_ps.wait()
        print ('read_ls_ps:\n%s' %read_ls_ps)
        if (((os.path.exists('/Volumes/%s' %nas_folder_path) is True)and(re.search('100.0% packet loss',read_ping_ps) is None))and((re.search('No such file or directory',read_ls_ps) is not None)or(len(read_ls_ps)!=0))):
            if os.path.exists('%s' %ffs_batch_folder_path):
                print('Connected to remote folder')
                #check if there is another FreeFileSync process openned
                freefilesync_app_ps = subprocess.Popen("ps -eaf | grep FreeFileSync", shell=True, stdout=subprocess.PIPE)
                freefilesync_read_ps = freefilesync_app_ps.stdout.read().decode('utf-8')
                freefilesync_app_ps.stdout.close()
                freefilesync_app_ps.wait()
                if re.search('FreeFileSync.app',freefilesync_read_ps) is None:
                    try:
                        #run batch file
                        subprocess.call(['open', "%s" %ffs_batch_file], cwd=ffs_batch_folder_path)
                        print('FreeFileSync.app started!')
                    except subprocess.CalledProcessError as e:
                        print ('Unable to sync, check batch file name and location: \n%s' %e)
                else:
                    print('Process already exists, another one was ignored till the previous one terminate!')
            else:
                ap = """ display dialog "Localhost folder not accessible, please contact your system administrator!" with title "Warning from Localhost Folder!" with icon stop buttons {"OK"} """
                subprocess.call("osascript -e '{}'".format(ap),shell=True)
                print ('Localhost folder not accessible!')
        else:
            #if ((os.path.exists('/Volumes/%s' %nas_folder_path)) is False)or(re.search('timeout',read_ping_ps) is None):
            ap = """ display dialog "Remote folder not mounted, please check your network connection and click Try again. If this problem persist contact your system administrator!" with title "Warning from Remote Folder!" with icon caution buttons {"Try again"} """
            subprocess.call("osascript -e '{}'".format(ap),shell=True)
            print('Remote folder is NOT mounted!')
            #time.sleep(sleep_period)
            if (os.path.exists('/Volumes/%s' %nas_folder_path) is False):
                try:
                    os.mkdir(local_mount_folder)
                except OSError as e:
                    print('%s' %e)
            try:
                mount_afp_ps = subprocess.Popen('mount_afp -i afp://%s:%s@%s/%s %s' %(u,p,ipnas,nas_folder_path,local_mount_folder), shell=True, stdout=subprocess.PIPE)
                read_mount_afp_ps = mount_afp_ps.stdout.read().decode('utf-8')
                mount_afp_ps.stdout.close()
                mount_afp_ps.wait()
            except OSError as e1:
                print('%s' %e)
            if (re.search('100.0% packet loss',read_ping_ps) is None)and(len(e1)==0):
                print ('Remote folder is NOW mounted!')
            else:
                print ('Remote folder is NOT mounted!')
        #sync period of time
        time.sleep(sleep_period)
 
if __name__=="__main__":
    run_ffs_batch()
User avatar
Site Admin
Posts: 7283
Joined: 9 Dec 2007

Zenju

Did you try the standard approach from the FFS manual? e.g.
1. create your FFS batch job and load it into RTS
2. Schedule RTS to run from startup
The description is for scheduling FFS with ffs_batch files, but should just as well work for other applications like RTS with ffs_real files.
Posts: 15
Joined: 20 Sep 2017

SipriusPT

Did you try the standard approach from the FFS manual? e.g.
1. create your FFS batch job and load it into RTS
2. Schedule RTS to run from startup
The description is for scheduling FFS with ffs_batch files, but should just as well work for other applications like RTS with ffs_real files. Zenju, 08 Nov 2017, 10:02
Thanks for the response Zenju, and sorry for the delay.

I tried the first approach that time but without success, RTS was not starting. The second one, I didnt try.

Also after some weeks of work, I notice with a certain type of file, I was unable to upload with FFS from my Macs to a remote folder, it was changing the way how Macos recognize those files when I was trying to access on the remote folder. But if I add the file on the remote folder, after running FFS, I was able to download it intact and use it as expected. In both cases I have checked that there was no losses of extended attributes(through unix shell).

After some tests, I notice that I had to copy and paste on the remote folder, I was unable to drag and drop holding cmd key(it performs a move, https://support.apple.com/en-us/HT201236). With cmd key I was having the same issue of FFS when it was uploading.

If you want I can give you those files.