워드프레스 자동 복구 쉘 스크립트 / WordPress Auto-Recovery Shell Script

구글드라이브/Google drive : https://drive.google.com/drive/folders/1VeFCOlbkxh1ZsUmn6JPfpTSYC_Qj0v9e?usp=drive_link

백업된 워드프레스 웹파일과 데이터 베이스 파일을 자동복구하는 쉘 스크립트 입니다.
This is a shell script that automatically restores backed up WordPress web files and database files.

수동으로 쉘스크립트를 실행해도 되고 crontab으로 쉘스크립트를 특정시간에 자동실행 시킬 수 있습니다.
You can run shell scripts manually or use crontab to automatically run shell scripts at specific times.

1.wp_restore_sample.sh

wp_restore_sample.sh파일을 열어서 아래의 굵은 글씨부분을 수정합니다.
Open the wp_restore_sample.sh file and modify the bold text below.

설정내용은 반드시 서버와 일치해야 합니다.
The settings must match the server.

# === 설정 / Settings ===
# 백업 파일들이 저장될 디렉토리 (절대 경로)
# 이 디렉토리에 tar.gz와 sql파일이 있어야 합니다.
# Directory where backup files will be stored (absolute path)
# There should be a tar.gz and sql file in this directory.
BACKUP_DIR="/home/ubuntu/backups"

# 웹 파일이 설치될 상위 디렉토리
# Parent directory where web files will be installed
WEB_ROOT="/var/www/html" 

# WordPress가 설치될 최종 디렉토리 이름 (예: /var/www/html/wordpress) 
# The final directory name where WordPress will be installed (e.g. /var/www/html/wordpress)
WP_DIR_NAME="wordpress" 

# 데이터베이스 계정 
# database account
DB_NAME="your_db_name" 
DB_USER="your_db_user" 
DB_PASSWORD="your_db_password" 
DB_HOST="localhost"

# WP_ROOT_PATH는 WordPress가 최종적으로 설치될 경로입니다.
# WP_ROOT_PATH is the path where WordPress will ultimately be installed.
WP_ROOT_PATH="${WEB_ROOT}/${WP_DIR_NAME}"

# 새로 복사할 wp-config.php 파일의 경로
# 이 파일에 대상 서버의 DB 정보가 정확히 설정되어 있어야 합니다!
# Path to the wp-config.php file to be newly copied
# This file must have the correct DB information set for the target server!
LOCAL_WP_CONFIG_PATH="/home/ubuntu/WordpressConfig/wp-config.php"

# --- 도메인 설정 / domain settings ---
# 이전 도메인 (원래 사이트 도메인)
# Previous domain (original site domain)
OLD_DOMAIN="https://www.yourdoman.com" 

# 새로운 도메인 (변경될 도메인)
# New domain (domain to be changed)
NEW_DOMAIN="https://www2.yourdomain.com" 

2.wp-config.php

— wp-config.php 파일을 열고 데이터베이스 정보를 수정합니다.
Open the wp-config.php file and edit the database information.

— 이 파일은 워드프레스 데이터베이스 설정파일로 쉘스크립스 실행시 복구될 워드프레스에 자동복사됩니다.
This file is the WordPress database configuration file and will be automatically copied to the WordPress to be restored when the shell script is executed.

define( 'DB_NAME', 'your_db_name' );

/** Database username */
define( 'DB_USER', 'your_db_user' );

/** Database password */
define( 'DB_PASSWORD', 'your_db_password' );

모든 설정이 완료되었으면 해당 디렉토리로 이동해서 sudo ./wp_restore_sample.sh를 실행합니다.
Once everything is set up, go to that directory and run sudo ./wp_restore_sample.sh.

정상적으로 실행되기 위해서는 반드시 sudo명령어로 관리자 권한으로 실행해야 합니다.
In order for it to run properly, you must run it with administrator privileges using the sudo command.

Leave a Reply

Your email address will not be published. Required fields are marked *