Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[PHP] 영카트5 DB 테이블별로 덤프하기

2018-08-31 by 편리

영카트5의 DB 데이터를 테이블별로 덤프하기 위한 코드이다. 코드 테스트는 PHP 7.0.x 버전, MariaDB 10.1.x 버전에서 완료했다.

<?php
require_once './_common.php';

$tables  = [];
$exclude = [
    'g5_autosave'
    'g5_visit',
    'g5_visit_sum'
];

$result = sql_query("SHOW TABLES");

for ($i = 0; $row = sql_fetch_array($result); $i++) {
    $tables[] = array_pop($row);
}

$userInfo = posix_getpwuid(fileowner(__FILE__));
$owner = $userInfo['name'];

$dir = '/home/dbbackup/'.$owner.'/'.date('Ymdhi');
mkdir($dir, 0755, true);

// 7일 초과 경과된 data 삭제
$basedir = dirname($dir);
$basetime = time() - 86400 * 7;

foreach (scandir($basedir) as $val) {
    if (in_array($val, array('.', '..')))
        continue;

    $d = $basedir.'/'.$val;

    if (filemtime($d) < $basetime) {
        if (is_dir($d)) {
            foreach (scandir($d) as $v) {
                if (in_array($v, array('.', '..')))
                    continue;

                if (is_file($d.'/'.$v))
                    @unlink($d.'/'.$v);
            }

            rmdir($d);
        } else {
            @unlink($d);
        }
    }
}

// DB 백업
$host = G5_MYSQL_HOST;
$user = G5_MYSQL_USER;
$pass = G5_MYSQL_PASSWORD;
$database = G5_MYSQL_DB;

foreach ($tables as $table) {
    if (in_array($table, $exclude))
        continue;

    $file = $dir.'/'.$table.'.sql';

    exec("mysqldump --user={$user} --password={$pass} --host={$host} {$database} {$table} --result-file={$file} 2>&1", $output);
}

$exclude 에 덤프 때 제외할 테이블을 지정할 수 있다.

Post navigation

Previous Post:

우분투 서버 nginx, php 7.2.x, mariadb 10.3.x 설치 스크립트

Next Post:

[쉘스크립트] 텍스트파일의 라인을 읽어 ip와 id 구분하기

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • SK 세븐모바일 유심 셀프교체
  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes