Example #1
0
def mysql_dump_auto(config, magento_root_path, backup_path, menu_return):
    x = datetime.datetime.now()
    current_date = x.strftime("%d%B%y")
    # Check if backups directory exists locally
    if not os.path.exists(backup_path):
        action = "Create Backup Folder"
        shell.run_bash_command(config, magento_root_path, action,
                               "mkdir -p " + backup_path,
                               "Backup Directory Created")

    if os.path.exists(backup_path + "/" + current_date + "_" +
                      config["db"]["connection"]["default"]["dbname"] +
                      ".sql"):
        os.remove(backup_path + "/" + current_date + "_" +
                  config["db"]["connection"]["default"]["dbname"] + ".sql")

    action = "Database Backup"
    shell.run_bash_command_popen(
        config, magento_root_path, action,
        "mysqldump --no-tablespaces --skip-lock-tables --opt --single-transaction --max_allowed_packet=512M -h mysql -u "
        + config["db"]["connection"]["default"]["username"] + " -p" +
        config["db"]["connection"]["default"]["password"] + " " +
        config["db"]["connection"]["default"]["dbname"] + " > " + backup_path +
        "/" + current_date + "_" +
        config["db"]["connection"]["default"]["dbname"] + ".sql", 1)
    print(Colors.FG.LightGreen + Colors.Bold +
          "MySQL Database Backed up to: " + backup_path + "/" + current_date +
          "_" + config["db"]["connection"]["default"]["dbname"] + ".sql" +
          Colors.Reset)

    if menu_return == 1:
        menu.mysql_menu(config, magento_root_path)
Example #2
0
def import_remote_database(settings_dict):
    # Fix SUPER Privs
    print(Colors.FG.LightGreen + Colors.Bold + "Fixing Super Privileges." +
          Colors.Reset)
    action = "Fix Super Privileges"
    shell.run_bash_command_popen(
        False, False, action,
        "sed -i 's/DEFINER=[^*]*\*/\*/g' /srv/backups/db_" +
        settings_dict["current_date"] + ".sql", 1)
    # Drop Old Database
    os.popen("mysql -h mysql -u " + settings_dict["dev_mysql_user"] + " -p'" +
             settings_dict["dev_mysql_password"] + "' -e 'drop database " +
             settings_dict["dev_mysql_database"] + "'").read()
    # Create Blank Database
    os.popen("mysql -h mysql -u " + settings_dict["dev_mysql_user"] + " -p'" +
             settings_dict["dev_mysql_password"] + "' -e 'create database " +
             settings_dict["dev_mysql_database"] + "'").read()
    # Import Fixed Dump
    print(Colors.FG.LightGreen + Colors.Bold +
          "Importing Production Database to Dev." + Colors.Reset)
    os.popen("mysql -h mysql -u " + settings_dict["dev_mysql_user"] + " -p'" +
             settings_dict["dev_mysql_password"] + "' " +
             settings_dict["dev_mysql_database"] + " < /srv/backups/db_" +
             settings_dict["current_date"] + ".sql").read()
    # Remove fixed database, keeping synced one for backup.
    os.popen("rm /srv/backups/db_" + settings_dict["current_date"] + ".sql")
Example #3
0
def update_mysql_credentials_manual(config, path, menu_return):
    action = "Update MySQL Credentials"
    db_creds = {}
    db_creds["Name"] = input(Colors.FG.Yellow + "MySQL Database: " +
                             Colors.Reset)
    db_creds["Username"] = input(Colors.FG.Yellow + "MySQL Username: "******"Password"] = input(Colors.FG.Yellow + "MySQL Password: "******"php -ddisplay_errors=on " + path +
            "/bin/magento setup:config:set --db-host mysql --db-name " +
            db_creds["Name"] + " --db-user " + db_creds["Username"] +
            " --db-password " + db_creds["Password"], 1)
        print(Colors.FG.LightGreen + Colors.Bold + action + " Completed!" +
              Colors.Reset)
    else:
        print(Colors.FG.Red + Colors.Bold +
              "Error getting database credentials." + Colors.Reset)
        print(Colors.FG.Red + Colors.Bold + action +
              " not completed. Returning to Menu." + Colors.Reset)
    if menu_return == 1:
        menu.mysql_menu(config, path)
Example #4
0
def install_cweagans(config, path):
    result = composer_check_cweagans(config, path)
    action = "Install cweagans"
    if result is False:
        shell.run_bash_command_popen(
            config, path, action,
            "cd " + path + "&& composer require cweagans/composer-patches", 1)
    else:
        print(Colors.FG.LightGreen + Colors.Bold + action +
              " already completed." + Colors.Reset)
Example #5
0
def backup_magento_no_media(config, magento_root_path, backup_path, menu_return):
    action = "Magento Root Backup"
    x = datetime.datetime.now()
    current_date = x.strftime("%d%B%y")
    print(Colors.FG.LightGreen + Colors.Bold + action + " Started." + Colors.Reset)
    if not os.path.exists(backup_path):
        action = "Create Backup Folder"
        shell.run_bash_command(config, magento_root_path, action, "mkdir -p " + backup_path, "Backup Directory Created")
    shell.run_bash_command_popen(config, magento_root_path, action, "tar --exclude=" + magento_root_path + "/var/* --exclude=" + magento_root_path + "/pub/media/* -zcf " + backup_path + "/backup_" + current_date + ".tar.gz " + magento_root_path, 1)
    if menu_return == 1:
        menu.magento_menu(config, magento_root_path)
Example #6
0
def config_sessions(config, path, menu_return):
    action = "Configure Redis Sessions"
    print(Colors.FG.LightGreen + Colors.Bold + action + " Started" +
          Colors.Reset)
    shell.run_bash_command_popen(
        config, path, action, "php -ddisplay_errors=on " + path +
        "/bin/magento setup:config:set --session-save=redis --session-save-redis-host=redis-session --session-save-redis-log-level=3 --session-save-redis-db=0 --session-save-redis-port=6380 --session-save-redis-disable-locking=1",
        1)
    print(Colors.FG.LightGreen + Colors.Bold + action + " Completed!" +
          Colors.Reset)
    if menu_return == 1:
        menu.redis_menu(config, path)
Example #7
0
def backup_local_auto(config, path, media, menu_return):
    x = datetime.datetime.now()
    current_date = x.strftime("%d%B%y")
    action = "Magento Local Backup"
    print(Colors.FG.LightGreen + "Starting " + action + Colors.Reset)
    mysql.mysql_dump_auto(config, path, path + "/database", 0)
    if media == 1:
        magento.backup_magento_basic(config, path, "/srv/backups/" + current_date, 0)
    else:
        magento.backup_magento_no_media(config, path, "/srv/backups/" + current_date, 0)

    action = "Backup Cleanup"
    print(Colors.FG.LightGreen + "Starting " + action + Colors.Reset)
    shell.run_bash_command_popen(config, path, action, "rm -rf " + path + "/database", 1)

    print(Colors.FG.LightGreen + "Magento Local Backup Complete: " + "/srv/backups/" + current_date + "/backup_" + current_date + ".tar.gz" + Colors.Reset)
    menu.magento_backup_menu(config, path)
Example #8
0
def config_cache(config, path, menu_return):
    action = "Configure Redis Config Cache"
    print(Colors.FG.LightGreen + Colors.Bold + action + " Started" +
          Colors.Reset)
    shell.run_bash_command_popen(
        config, path, action, "php -ddisplay_errors=on " + path +
        "/bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=redis-config-cache --cache-backend-redis-db=0 --cache-backend-redis-port=6381",
        1)

    action = "Configure Redis FPC"
    print(Colors.FG.LightGreen + Colors.Bold + action + " Started" +
          Colors.Reset)
    shell.run_bash_command_popen(
        config, path, action, "php -ddisplay_errors=on " + path +
        "/bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=redis --page-cache-redis-db=0 --page-cache-redis-port=6379",
        1)
    if menu_return == 1:
        menu.redis_menu(config, path)
Example #9
0
def mysql_dump_manual(config, magento_root_path, menu_return):
    x = datetime.datetime.now()
    current_date = x.strftime("%d%B%y")
    backup_path = input(Colors.FG.Yellow +
                        "Path to dump database to? Default: /srv/backups: " +
                        Colors.Reset)
    if backup_path == "":
        backup_path = "/srv/backups"
    elif backup_path.endswith("/"):
        path_length = len(backup_path)
        backup_path = backup_path[:path_length - 1]

    db_name = input(Colors.FG.Yellow + "MySQL Database: " + Colors.Reset)
    db_username = input(Colors.FG.Yellow + "MySQL Username: "******"MySQL Password: "******"Create Backup Folder"
        shell.run_bash_command(config, magento_root_path, action,
                               "mkdir -p " + backup_path,
                               "Backup Directory Created")

    if os.path.exists(backup_path + "/" + current_date + "_" + db_name +
                      ".sql"):
        os.remove(backup_path + "/" + current_date + "_" + db_name + ".sql")

    action = "Database Backup"
    shell.run_bash_command_popen(
        config, magento_root_path, action,
        "mysqldump --no-tablespaces --skip-lock-tables --opt --single-transaction --max_allowed_packet=512M -h mysql -u "
        + db_username + " -p" + db_password + " " + db_name + " > " +
        backup_path + "/" + current_date + "_" + db_name + ".sql", 1)
    print(Colors.FG.LightGreen + Colors.Bold +
          "MySQL Database Backed up to: " + backup_path + "/" + current_date +
          "_" + db_name + ".sql" + Colors.Reset)
    if menu_return == 1:
        menu.mysql_menu(config, magento_root_path)
Example #10
0
def backup_local_custom(config, path, media, menu_return):
    x = datetime.datetime.now()
    current_date = x.strftime("%d%B%y")
    action = "Magento Local Backup"
    print(Colors.FG.LightGreen + "Starting " + action + Colors.Reset)
    mysql.mysql_dump_auto(config, path, path + "/database", 0)
    backup_path = input(Colors.FG.Yellow + "Backup Path: Default - /srv/backups: " + Colors.Reset)
    if backup_path == "":
        backup_path = "/srv/backups"
    elif backup_path.endswith("/"):
        path_length = len(backup_path)
        backup_path = backup_path[:path_length - 1]
    if media == 1:
        magento.backup_magento_basic(config, path, backup_path + "/" + current_date, 0)
    else:
        magento.backup_magento_no_media(config, path, backup_path + "/" + current_date, 0)

    action = "Backup Cleanup"
    print(Colors.FG.LightGreen + "Starting " + action + Colors.Reset)
    shell.run_bash_command_popen(config, path, action, "rm -rf " + path + "/database", 1)

    print(Colors.FG.LightGreen + "Magento Local Backup Complete: " + backup_path + "/" + current_date + "/backup_" + current_date + ".tar.gz" + Colors.Reset)
    menu.magento_backup_menu(config, path)
Example #11
0
def reset_crons(config, path, menu_return):
    action = "Reset Crons"
    shell.run_bash_command(config, path, "Stop Crons",
                           "/usr/share/stratus/cli crons.stop",
                           "Stopped Cron Jobs")
    shell.run_bash_command_popen(
        config, path, "Delete Cron Schedule from Database",
        "mysql -h mysql -u " +
        config["db"]["connection"]["default"]["username"] + " -p\"" +
        config["db"]["connection"]["default"]["password"] + "\" " +
        config["db"]["connection"]["default"]["dbname"] + " -e 'delete from " +
        config["db"]["table_prefix"] + "cron_schedule'", 1)
    shell.run_bash_command(config, path, action,
                           "rm -rf " + path + "/var/cron/*",
                           "Cleared " + path + "/var/cron/")
    shell.run_bash_command(config, path, action,
                           "/usr/share/stratus/cli crons.start",
                           "Started Cron Jobs")
    print(Colors.FG.LightGreen + Colors.Bold + action + " Completed." +
          Colors.Reset)
    time.sleep(1.5)
    if menu_return == 1:
        menu.cron_menu(config, path)
Example #12
0
def backup_to_s3_bucket(config, path, menu_return):
    x = datetime.datetime.now()
    current_date = x.strftime("%d%B%y")
    action = "S3 Bucket Upload"
    print(Colors.FG.LightGreen + "Starting " + action + Colors.Reset)
    s3_bucket = input(Colors.FG.Yellow + "S3 Bucket Name: " + Colors.Reset)
    mysql.mysql_dump_auto(config, path, path + "/database", 0)
    magento.backup_magento_basic(config, path, "/srv", 0)
    shell.run_bash_command_popen(config, path, action, "aws s3 cp /srv/backup_" + current_date + ".tar.gz s3://" + s3_bucket, 1)
    action = "Backup Cleanup"
    print(Colors.FG.LightGreen + "Starting " + action + Colors.Reset)
    action = "Remove Backup Archive"
    shell.run_bash_command_popen(config, path, action, "rm -f /srv/backup_" + current_date + ".tar.gz", 1)
    action = "Remove Backup Database"
    shell.run_bash_command_popen(config, path, action, "rm -rf " + path + "/database", 1)
    menu.magento_backup_menu(config, path)
Example #13
0
def composer_lock(config, path):
    action = "Composer Update Lock"
    shell.run_bash_command_popen(config, path, action,
                                 "cd " + path + "&& composer update --lock", 1)
Example #14
0
def composer_install(config, path):
    action = "Composer Install"
    shell.run_bash_command_popen(config, path, action,
                                 "cd " + path + "&& composer -v install", 1)
Example #15
0
def rsync_production_files(settings_dict):
    action = "RSYNC Prod Files to Dev."

    # remove the root path on dev instance
    if os.path.exists(settings_dict["prod_public_html"]):
        shell.run_bash_command_popen(False, False, action, "rm -rf " + settings_dict["prod_public_html"], "")

    print(Colors.FG.LightGreen + Colors.Bold + "Starting " + action + Colors.Reset)
    if settings_dict["root_is_symlink"] is True:
        # remove last portion of link path for rsync target
        new = settings_dict["root_symlink"]["link_path"].split("/")
        for l in new:
            if l == "":
                new.remove(l)
        new_path = "/"
        list_length = len(new) - 1
        for l in range(list_length):
            new_path += new[l] + "/"

        if not os.path.exists(new_path):
            child = subprocess.Popen("mkdir -p " + new_path, shell=True, stdout=subprocess.PIPE)
            streamdata = child.communicate()[0]
            rc = child.returncode

        # rsync link path to dev from production
        shell.run_bash_command_popen(False, False, action,
                                     "rsync -Pavl -e 'ssh -p " + settings_dict["prod_ssh_port"] + " -i " +
                                     settings_dict[
                                         "prod_ssh_privkey_path"] + "' " + settings_dict["prod_ssh_user"] + "@" +
                                     settings_dict["prod_ssh_host"] + ":" +
                                     settings_dict["root_symlink"]["link_path"] + " " + new_path, ".")
        # recreate symlink
        shell.run_bash_command(False, False, action, "ln -s " + settings_dict["root_symlink"]["link_path"] + " " + settings_dict["prod_public_html"], "..")
    else:
        # remove last portion of root path for rsync target
        new = settings_dict["prod_public_html"].split("/")
        for l in new:
            if l == "":
                new.remove(l)
        new_path = "/"
        list_length = len(new) - 1
        for l in range(list_length):
            new_path += new[l] + "/"

        if not os.path.exists(new_path):
            child = subprocess.Popen("mkdir -p " + new_path, shell=True, stdout=subprocess.PIPE)
            streamdata = child.communicate()[0]
            rc = child.returncode

        # rsync root from production to dev using rsync target
        shell.run_bash_command_popen(False, False, action, "rsync -Pavl -e 'ssh -p " + settings_dict["prod_ssh_port"] + " -i " + settings_dict[
            "prod_ssh_privkey_path"] + "' " + settings_dict["prod_ssh_user"] + "@" + settings_dict["prod_ssh_host"] + ":" +
                 settings_dict["prod_public_html"] + " " + new_path, ".")
        # print second set of . to keep visual progress.
        print(Colors.FG.LightGreen + Colors.Bold + ".." + Colors.Reset)

    # check if we have folder inside root that are symlinks
    if settings_dict["symlink_folders"] is not False:
        count = 3
        folder_list = list(settings_dict["symlink_folders"])
        for f in folder_list:
            # remove folder on dev if exists
            if os.path.exists(f):
                shell.run_bash_command_popen(False, False, action, "rm -rf " + f, "")
            # remove last folder of path ex "/srv/public_html/var" to "/srv/public_html"
            new = f.split("/")
            for l in new:
                if l == "":
                    new.remove(l)
            new_path = "/"
            list_length = len(new) - 1
            for p in range(list_length):
                new_path += new[p] + "/"

            success_message = "." * count
            # create directory if it doesn't exist
            if not os.path.exists(new_path):
                shell.run_bash_command_popen(False, False, action, "mkdir -p " + new_path, success_message)
            count += 1
            success_message = "." * count
            shell.run_bash_command_popen(False, False, action,
                                         "rsync -Pavl -e 'ssh -p " + settings_dict["prod_ssh_port"] + " -i " +
                                         settings_dict[
                                             "prod_ssh_privkey_path"] + "' " + settings_dict["prod_ssh_user"] + "@" +
                                         settings_dict["prod_ssh_host"] + ":" +
                                         f + " " + new_path,
                                         success_message)
            count += 1
    print(Colors.FG.LightGreen + Colors.Bold + action + " Complete!" + Colors.Reset)