Source

woocode / sa-auto / sh / backup / back_local.sh

Full commit
#!/bin/sh

CWD=$(dirname $(which $0))
. $CWD/config.sh

init_dir() {
    mkdir -p $HOST_BACKUP_DIR
}

backup_mysql() {

    MY_DBS=`$MYSQL -u${MY_USER}  --password="${MY_PASS}" -h ${MY_HOST} -Bse "show databases"`

    for DB in $MY_DBS;
    do
        # exclude information_schema
        if [ "$DB" = "information_schema" ]
        then
            continue
        elif [ "$DB" = "mysql" ]
        then
            continue
        fi
        echo "backup $DB";
        $MYDUMP -u${MY_USER} --password="${MY_PASS}" -h ${MY_HOST} ${DB} | gzip  > ${HOST_BACKUP_DIR}/${HOST}_mydb_${DB}_${VAR_DATE}.gz

    done
}


backup_dat_dir() {
   tar zcf $HOST_BACKUP_DIR/${HOST}_dat_${1}_${VAR_DATE}.tgz /apps/dat/${1}
}

backup_apps_dir() {
   tar zcf $HOST_BACKUP_DIR/${HOST}_apps_${1}_${VAR_DATE}.tgz /apps/${1}
}

backup_conf() {
   tar zcf $HOST_BACKUP_DIR/${HOST}_conf_${VAR_DATE}.tgz /apps/conf
}

sync_backup() {
    test -z "${SYNC_ALL}" && DEST="host_${HOST}/" || DEST=""
   /apps/rsync/update_rsync.py $1 bak/$DEST $RSYNC_EXR_ARGS
}

backup_pg_cms() {
    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    export PGDATA=/apps/dbdat/pg_data
    PG_DUMP=/apps/svr/postgres/bin/pg_dump

    $PG_DUMP -C -E "UTF-8" -U cms cmsdb | gzip > $HOST_BACKUP_DIR/${HOST}_pgdat_cmsdb_${VAR_DATE}.gz
    # keep a fresh backup
    /apps/sh/pg_dump.sh cmsdb
}

backup_pg_fe001() {
    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    export PGDATA=/apps/dbdat/pg_data
    PG_DUMP=/apps/svr/postgres/bin/pg_dump

    $PG_DUMP -C -E "UTF-8" -U fetip fe001 | gzip > $HOST_BACKUP_DIR/${HOST}_pgdat_fe001_${VAR_DATE}.gz
    # keep a fresh backup
    /apps/sh/pg_dump.sh fe001
}

init_dir
test -n "$BACKUP_MYSQL" && backup_mysql
test -n "$BACKUP_CONF" && backup_conf
test -n "$BACKUP_DAT_DIRS" && for dir in $BACKUP_DAT_DIRS; do backup_dat_dir $dir; done
test -n "$BACKUP_APPS_DIRS" && for dir in $BACKUP_APPS_DIRS; do backup_apps_dir $dir; done
test -n "$SYNC_TO_IP" && sync_backup $SYNC_TO_IP
test -n "$BACKUP_PG_CMS" && backup_pg_cms
test -n "$BACKUP_PG_FE001" && backup_pg_fe001