조회 수 858 추천 수 1 댓글 1
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
Extra Form
라이선스 MIT
#!/bin/bash

# Copyright (C) 2017 Study For Us HOSTING (https://hosting.studyforus.com)
# The Site Mirroring Tool (For RHYMIX)
# Version information : 0.1 (Proto type)
# License : The MIT License (MIT)

# DEFINE ORIGINAL SERVER VARS
ORIGIN_HOST='ORIGIN_server_host'# ORIGINAL SERVER HOST
ORIGIN_DB_HOST='db_host'# ORIGINAL DB HOST
ORIGIN_DB_NAME='db_name'# ORIGINAL DB NAME
ORIGIN_DB_USER='db_user_name'# ORIGINAL DB USER NAME
ORIGIN_DB_PASSWD='db_user_password'# ORIGINAL DB USER PASSWORD
ORIGIN_WEB_DIR='absolute_file_path'# ONLY ABSOLUTE PATH
ORIGIN_USER='user_name'# SSH USER NAME
ORIGIN_DOMAIN='www.domain.com'# ORIGINAL DOMAIN URL
DB_PREFIX='rx_'# DB PREFIX (Basically rx_ or xe_)

# DEFINE MIRROR SERVER VARS
MIRROR_HOST='hostname'# MIRROR SERVER HOST
MIRROR_DB_HOST='db_host'# MIRROR DB HOST
MIRROR_DB_NAME='new_db_name'# MIRROR DB NAME
MIRROR_DB_USER='new_db_user'# MIRROR DB USER NAME
MIRROR_DB_PASSWD='new_db_password'# MIRROR DB USER PASSWORD
MIRROR_WEB_DIR='new_web_path'# MIRROR WEB DIRECTORY (ABSOLUTE PATH)
MIRROR_DOMAIN='www.mirror.com'# MIRROR DOMAIN URL


# Move to web directory.
echo "Move to new web diretory."
cd $MIRROR_WEB_DIR

# Dumping original DB to web directory on mirror server.
echo "Dumping DB to new web directory."
mysqldump -h$ORIGIN_DB_HOST -u$ORIGIN_DB_USER --password=$ORIGIN_DB_PASSWD  --single-transaction $ORIGIN_DB_NAME > $ORIGIN_DB_NAME.sql
echo ""
echo "done."
echo ""
echo ""

# Copying the original DB to new DB.
echo "Restore DB to new site."
mysql -h$MIRROR_DB_HOST -u$MIRROR_DB_USER --password=$MIRROR_DB_PASSWD  $MIRROR_DB_NAME < $ORIGIN_DB_NAME.sql
echo ""
echo "done."
echo ""
echo ""


# Delete DB file after dumping.
echo "Removing DB backup file."
rm $ORIGIN_DB_NAME.sql
echo ""
echo "done."
echo ""
echo ""

# Copying web files to mirror server via rsync
echo "Coping web files to new site web directory."
rsync -azh --delete $ORIGIN_USER@$ORIGIN_HOST:$ORIGIN_WEB_DIR/ $MIRROR_WEB_DIR/
echo ""
echo "done."
echo ""
echo ""

# Back up config.php file
echo "Back up config file."
cp files/config/config.php files/config/config.php.bak
echo ""
echo "done."
echo ""
echo ""

# Modifying DB information from config.php
echo "Changing DB information in config.php file"
sed -i "s/$ORIGIN_DB_NAME/$MIRROR_DB_NAME/g" $MIRROR_WEB_DIR/files/config/config.php
echo "DB name changed."
sed -i "s/$ORIGIN_DB_USER/$MIRROR_DB_USER/g" $MIRROR_WEB_DIR/files/config/config.php
echo "DB user name changed"
sed -i "s/$ORIGIN_DB_PASSWD/$MIRROR_DB_PASSWD/g" $MIRROR_WEB_DIR/files/config/config.php
echo "DB password changed."
echo ""
echo "All DB information changed."
echo ""
echo ""

# Changing domain name in DB. 
echo "Changing site domain information to information in DB."
mysql -h$MIRROR_DB_HOST -u$MIRROR_DB_USER -p$MIRROR_DB_PASSWD $MIRROR_DB_NAME -e "UPDATE ${DB_PREFIX}domains SET domain = \"${MIRROR_DOMAIN}\" WHERE domain = \"${ORIGIN_DOMAIN}\";"
mysql -h$MIRROR_DB_HOST -u$MIRROR_DB_USER -p$MIRROR_DB_PASSWD $MIRROR_DB_NAME -e "UPDATE ${DB_PREFIX}sites SET domain = \"${MIRROR_DOMAIN}\" WHERE domain = \"${ORIGIN_DOMAIN}\";"
echo ""
echo "done."
echo ""
echo "Site migration(mirroring) complete."


처음 부분에 변수만 설정해주고 실행하면 자동으로 서버 이전이 완료됩니다.

  • profile
    이니스프리 2018.01.14 20:23
    그러지 않아도 미러링에 대해 공부하고 싶었는데 감사합니다! ^-^

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
38 코드 잘못 쓰면 컴퓨터가 날아가는 코드 29 제르엘 2018.07.08 964
37 코드 매우 특이한 버그 9 title: 대한민국 국기gimmepoint 2018.06.05 569
36 내가 만든 merge sort 3 title: 대한민국 국기gimmepoint 2018.05.17 370
35 코드 내가 만든 함수 모음집 2 title: 대한민국 국기gimmepoint 2018.05.12 379
34 코드 내가 만든 사칙연산 계산기 title: 대한민국 국기gimmepoint 2018.05.11 515
33 코드 내가 만든 함수 모음집 4 title: 대한민국 국기gimmepoint 2018.05.08 382
32 코드 클라이언트단에서 이미지 리사이징 6 file 네모 2018.05.06 1069
31 코드 HEX를 RGB로, RGB를 HEX로 바꾸는 PHP 코드 1 네모 2018.05.05 507
30 코드 c 이진트리 전,중,후위 알고리즘 2 title: 대한민국 국기gimmepoint 2018.04.24 495
29 코드 html 초보가 만든 자소서 4 title: 대한민국 국기gimmepoint 2018.04.21 651
28 코드 Hello, World!를 출력해보자 18 네모 2018.04.21 568
27 코드 아주 간단한 기초 C++ 6 제르엘 2018.04.21 477
26 코드 미완성 받아쓰기 (C) title: 대한민국 국기gimmepoint 2018.04.20 380
25 코드 Cmd 에서 서비스 시작 / 종료하기 1 ProjectSE 2018.02.18 644
24 코드 CMD로 로컬 연결 고정 IP 설정하기 1 title: 황금 서버 (30일)humit 2018.02.06 1038
23 코드 컴퓨터의 uuid 얻기 5 title: 황금 서버 (30일)humit 2018.01.28 1097
22 코드 유튜브에 약간의 기능을 추가 해주는 크롬 확장 프로그램. 11 file Hanam09 2018.01.26 942
» 코드 사이트 서버 이전 (또는 미러링 사이트 구축) 쉽게하는 스크립트 1 NoYeah 2018.01.14 858
20 코드 새 글 자동 댓글 스크립트 (AutoHotkey) 9 이니스프리 2017.11.26 3451
19 코드 파이썬을 이용한 텔레그램 새 글 알림 (허접합니다) 4 이니스프리 2017.11.19 2376
Board Pagination Prev 1 2 3 4 Next
/ 4