#! /usr/bin/python3 # !IMPORTANT: Make sure this is installed already: https://github.com/andreafabrizi/Dropbox-Uploader import subprocess import time from datetime import datetime as dt import os if __name__ == "__main__": _start_time = float(time.perf_counter()) now = dt.now() dt_string = now.strftime("%H%M%S_%m_%d_%Y") home_dir = "/home/cabox/workspace" arch_file_name = "WesternReload_wpcontent_" + dt_string + ".zip" wp_cli_cmd = subprocess.run(["wp", "db", "export"]) print("wp db export: %d" % wp_cli_cmd.returncode) # # zip up the wp-content dir zip_cmd = subprocess.run(["zip", "-r", arch_file_name, "wp-content/"]) print("zip wpcontent dir: %d" % zip_cmd.returncode) # # add the exported sql file to the zip archive zip_cmd = subprocess.run(["zip", "-g", arch_file_name, "*.sql"]) print("add sql file: %d" % zip_cmd.returncode) # # add wp-config file to the zip archive zip_cmd = subprocess.run(["zip", "-g", arch_file_name, "wp-config.php"]) print("add config file: %d" % zip_cmd.returncode) # # bash dropbox_uploader.sh upload ../WesternReload_wpcontent_bkup_114810_10_29_2021.zip WRC upload_cmd_cmd = subprocess.run(["bash", "dropboxup/dropbox_uploader.sh", "upload", arch_file_name, arch_file_name]) print("uploading file: %d" % upload_cmd_cmd.returncode) # remove the sql and archive files print("Cleanup ... ") files_in_directory = os.listdir(home_dir) filtered_files = [file for file in files_in_directory if file.endswith(".zip") or file.endswith(".sql")] for file in filtered_files: path_to_file = os.path.join(home_dir, file) print("\t deleting ", path_to_file) os.remove(path_to_file) _end_time = float(time.perf_counter()) _total_time = round(_end_time - _start_time, 2) print("Finished in " + str(_total_time) + " second(s)")