mysql dump hive_Hive元数据备份

#!/bin/bash

###############################################################################

# FileName: MysqlBackupScript

# Author: chenzheng

# Version: 1.0

# Description: Backup Mysql Database

# Histroy:

# Version: v1.0

# Date: 20140703

##############################################################################

# your MySQL server's name

SERVER="Hadoop4"

# directory to backup to

BACKDIR=~/MysqlBackups

# date format that is appended to filename

DATE=`date +'%Y-%m-%d'`

#----------------------MySQL Settings--------------------#

# your MySQL server's location (IP address is best)

HOST=10.190.113.999

# MySQL username

USER=hive

# MySQL password

PASS=xxxxoooo

# List all of the MySQL databases that you want to backup in here,

# each separated by a space

DBS="hive"

# set to 'y' if you want to backup all your databases. this will override

# the database selection above.

DUMPALL=n

#----------------------FTP Settings--------------------#

# set "FTP=y" if you want to enable FTP backups

FTP=n

# FTP server settings; should be self-explanatory

FTPHOST="10.190.113.999:21"

FTPUSER="hadoop"

FTPPASS="xxxx0000"

# directory to backup to. if it doesn't exist, file will be uploaded to

# first logged-in directory

FTPDIR="backups"

#-------------------Deletion Settings-------------------#

# delete old files?

DELETE=n

# how many days of backups do you want to keep?

DAYS=30

#----------------------End of Settings------------------#

# check of the backup directory exists

# if not, create it

if [ -e $BACKDIR ]

then

echo "Backups directory already exists !"

else

mkdir $BACKDIR

echo "Create backup directory succeed !"

fi

if [ $DUMPALL = "y" ]

then

echo "Creating list of all your databases..."

mysql -h $HOST --user=$USER --password=$PASS -e "show databases;" > ~/dbs_on_$SERVER.txt

# redefine list of databases to be backed up

DBS=`sed -e ':a;N;$!ba;s/\n/ /g' -e 's/Database //g' ~/dbs_on_$SERVER.txt`

fi

echo "Backing up MySQL databases..."

for database in $DBS

do

mysqldump -h $HOST --user=$USER --password=$PASS $database > $BACKDIR/$SERVER-mysqlbackup-$database-$DATE.sql

gzip -f -9 $BACKDIR/$SERVER-mysqlbackup-$database-$DATE.sql

done

if [ $FTP = "y" ]

then

echo "Initiating FTP connection..."

cd $BACKDIR

ATTACH=`for file in *$DATE.sql.gz; do echo -n -e "put ${file}\n"; done`

ftp -nv <

open $FTPHOST

user $FTPUSER $FTPPASS

cd $FTPDIR

$ATTACH

quit

EOF

echo -e "FTP transfer complete! \n"

fi

if [ $DELETE = "y" ]

then

NEWDATE=`date --date='30 days ago' +'%Y-%m-%d'`

rm -rf $BACKDIR/$SERVER-mysqlbackup-$database-$NEWDATE.sql.gz

echo "The backup from $DAYS days ago has been deleted."

fi

echo "Your backup is complete!"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值