def backup_to_server(): print("####{} backup_function.py####".format( dt.datetime.now().strftime('%Y-%m-%d_%H_%M'))) ##replace this with appropriate local & remote paths for backup if "gustavo" in socket.gethostname(): copy_from = "/home/gustavo/T**S/VIDEOS/" copy_to = "/run/user/1001/gvfs/smb-share:server=r-zfssvr01,share=grplucy/Videos_GRETI/field_season_winter_2020/" else: copy_from = "/home/michael/T**S/VIDEOS/" copy_to = "/mnt/Videos_GRETI/field_season_winter_2020/" #Get a list of files in original folder files_from = os.listdir(copy_from) #Get a list of files in backup folder files_bup = os.listdir(copy_to) files_to_bup = np.setdiff1d(files_from, files_bup) #Copy Video files print("backing up {} files".format(len(files_to_bup))) for video in files_to_bup: try: command = 'mv {}{} {}'.format(copy_from, video, copy_to) terminal(command) except Exception as e: print(e) print( "Error uploading {} to server. Uploading to overflow folder to avoid merge error." .format(video)) try: command = 'mv {}{} {}overflow/'.format(copy_from, video, copy_to) print(command) terminal(command) except Exception as e: print( "A further error has occurred. Manually remove files to save data." ) else: print("All files backed up")
def server_check(): server = [] for pi in pi_data_table: print("Checking server mount in {}".format(pi)) reachable = ping_pi(pi[1]) if not reachable: print("{} not responding to pings".format(pi[0])) info = "NA" else: info = terminal( "ssh pi@{} '[ -d \"/home/pi/mnt/Videos_GRETI\" ] && echo \"Server is mounted\" || echo \"Server is NOT mounted\"'" .format(pi[1])) server += [info] return server
source = "~/raspi_tit_scripts/data/*" for pi in pi_data_table: if "Puzzle" in pi[0]: target_pop = re.search("P\d?\d", pi[0]).group(0) print("Downloading puzzle data from {}".format(target_pop)) reachable = ping_pi(pi[1]) if not reachable: pass else: try: copy_to = "{}/{}".format(destination, target_pop) command = 'rsync -a --exclude \'*.md\' pi@{}:{} {}'.format( pi[1], source, copy_to) print(command) terminal(command) except Exception as e: print("Error moving files: {}".format(e)) pass else: pass env_pis = [["EnvInfoD4", "10.76.0.52"], ["EnvInfoC1", "10.76.0.53"], ["EnvInfoD3", "10.76.0.54"], ["EnvInfoG10", "10.76.0.57"]] destination = "~/T**S/env_data" source = "~/env_info_code/data/*" for pi in env_pis: print("downloading env data {}".format(pi)) reachable = ping_pi(pi[1])
print("####{} write_to_crontab.py####".format( dt.datetime.now().strftime('%Y-%m-%d_%H_%M'))) for pi in pi_data_table: print("Writing to crontab for {}".format(pi)) reachable = ping_pi(pi[1]) if not reachable: pass else: #command = "ssh pi@{} \'\'".format(pi[1]) #command = "ssh pi@{} mkdir /home/pi/mnt".format(pi[1]) #command = "ssh pi@{} \'set +H;echo -e \"username=mchimento\npassword=***\ndomain=top.orn.mpg.de\" | sudo tee /etc/.smbcredentials;mkdir /home/pi/mnt; echo -e \"//10.0.16.7/grpLucy /home/pi/mnt cifs x-systemd.automount,credentials=/etc/.smbcredentials,uid=pi,gid=pi,vers=3.0 0 0\" | sudo tee -a /etc/fstab\'".format(pi[1]) #the command below disables hdmi out. -p to re-enable #command= "ssh pi@{} \"echo \"/usr/bin/tvservice -o\" | sudo tee -a /etc/rc.local; sudo reboot\"".format(pi[1]) #allocate 256 mb to gpu #command= "ssh pi@{} \"echo \"gpu_mem=256\" | sudo tee -a /boot/config.txt; sudo reboot\"".format(pi[1]) #command = "ssh pi@{} \"sudo sed -i '$ d' /etc/fstab\"".format(pi[1]) command = "ssh pi@{} \"echo -e \"//10.0.16.7/grpLucy_Videos_GRETI /home/pi/mnt cifs x-systemd.automount,credentials=/etc/.smbcredentials,uid=pi,gid=pi,vers=3.0 0 0\" | sudo tee -a /etc/fstab\"".format( pi[1]) command = "ssh pi@{} \'pip3 install psutil\'".format(pi[1]) try: print(command) response = terminal(command) print(response) except Exception as e: print("{}, error writing to file".format(e)) #reboot(pi[1])
#!/usr/bin/python3 import datetime as dt import os import sys from all_ipsandnames import pi_data_table from term_utils import ping_pi, terminal, kill_python, reboot, take_test_img print("####{} get_test_img.py####".format(dt.datetime.now().strftime('%Y-%m-%d_%H_%M'))) #clear out yesterday's photos copy_to = "~/T**S/daily_check" copy_from = "APAPORIS/CURRENT" command = 'rm -rf {}/*.jpg'.format(copy_to) terminal(command) for pi in pi_data_table: print("Attempting to take picture from {}".format(pi)) reachable = ping_pi(pi[1]) if not reachable: pass else: if "Puzzle" not in pi[0]: #return most recently created image command = "ssh pi@{} \"cd {} && ls -t | head -n1\"".format(pi[1],copy_from) print(command) most_recent_folder = terminal(command).strip(" \n") print(most_recent_folder) command = "ssh pi@{} \"cd {}/{} && ls -t | head -n1\"".format(pi[1],copy_from,most_recent_folder) print(command) most_recent_img = terminal(command).strip()