조회 수 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
번호 분류 제목 글쓴이 날짜 조회 수
58 코드 [JS] http를 https로 리디렉션! 3 Hanam09 2018.12.30 674
57 코드 [JS] 클라이언트단 GET Parameter Hanam09 2019.11.16 467
56 코드 [JS]클라이언트에서 Ip를 얻어보자 2 Hanam09 2019.01.21 625
55 코드 [PHP/Javascript] 아미나에 자동으로 게시글을 생성하고 Ajax로 전송하여 결과를 표시하기 2 file 이니스프리 2019.07.09 777
54 코드 [PHP] 간단한 캐싱 클래스 3 title: 황금 서버 (30일)humit 2018.12.06 605
53 코드 [PHP] 그누보드 자동 게시글 작성 - 일본기상협회의 우리나라 날씨를 크롤링한 후 파파고로 번역하여 글 작성 4 file 이니스프리 2018.11.15 657
52 코드 [PHP] 기상청 RSS 시간별 예보 위젯 - cache 적용(?) 9 file 이니스프리 2018.10.28 850
51 코드 [PHP] 기상청 중기예보를 캐러셀로 보여주는 위젯 (매우 허접합니다 ㅠㅠ) 10 file 이니스프리 2018.09.28 647
50 코드 [PHP] 이미지를 원하는 크기(원본비율 유지)로 리사이즈 하여 출력 (원본 이미지는 수정하지 않습니다) 6 이니스프리 2018.12.20 7714
49 코드 [PyQt] sir.kr에서 스크랩한 게시글을 보여주는 윈도우앱 (검색 및 정렬 가능) 7 file 이니스프리 2019.08.09 1000
48 코드 [Python-Gnuboard] 파이썬으로 구현한 그누보드 자동 글쓰기 함수 1 file 이니스프리 2021.04.08 1224
47 코드 [Python/Telegram] Studyforus 알림봇 (댓글, 스티커 파싱) 7 file 이니스프리 2020.05.15 650
46 코드 [Python] Google Image Search 결과를 받아오기 file 이니스프리 2019.12.09 949
45 코드 [Python] PIL을 이용한 Animated GIF의 리사이징 file 이니스프리 2019.11.03 1103
44 코드 [Python] Selenium을 이용하여 특정 element를 캡처하는 스크립트 2 file 이니스프리 2019.07.03 5934
43 코드 [Python] url 주소로부터 IP 주소 알아내기 title: 황금 서버 (30일)humit 2020.02.20 2064
42 코드 [Python] 네이버 모바일 이미지 검색에서의 이미지 파일을 멀티스레드로 다운받고 1개의 파일로 병합 11 file 이니스프리 2019.07.12 1378
41 코드 [Python] 네이버 실시간 검색어 3 title: 황금 서버 (30일)humit 2020.01.23 1125
40 코드 [Python] 모 정부기관 사이트 파싱 후 PC 통신처럼 열람하고 싶은 게시글 번호를 입력하면 내용을 보여주는 소스 (허접) 4 이니스프리 2018.09.14 559
39 코드 [Python] 선택한 파일을 Dropbox API를 이용하여 업로드하고 공유링크를 받아서 이미지 호스팅 용도로 URL을 변환하기 1 file 이니스프리 2019.07.02 1005
Board Pagination Prev 1 2 3 4 Next
/ 4