备份数据库命令

目录

MySQL

1
2
3
4
5
6
7
8
# 导出
mysqldump -u"$user" -p"$passwd" db_name > ~/backup/db_name.sql

# 拷贝
scp user@xx.xx.xx.xx:/home/user/backup/db_name.sql ~/Downloads

# 导入
mysql -u"$user" -p"$passwd" -f db_name < ~/Downloads/db_name.sql

Mongo

1
2
3
4
5
6
7
8
# 导出
mongodump -h 127.0.0.1:27017 –authenticationDatabase admin -u user -p password -d logs -o ~/backup/

# 拷贝
scp -r user@xx.xx.xx.xx:/home/user/backup/logs ~/Downloads

# 导入
mongorestore -h 127.0.0.1:27017 -d logs ~/Downloads/logs

Redis

1
2
3
4
5
6
7
8
# 安装
gem install redis-dump

# 导出
redis-dump -u 127.0.0.1:6379 -a password -d 1 > /path/to/redis.json

# 导入
cat /path/to/redis.json | redis-load -u 127.0.0.1:6379

Elasticsearch

1
2
3
4
5
6
7
# 安装
npm i -g elasticdump

# 同步
elasticdump –input=http://src_ip:9200/index_name –output=http://dest_ip:9200/index_name –type=analyzer
elasticdump –input=http://src_ip:9200/index_name –output=http://dest_ip:9200/index_name –type=mapping
elasticdump –input=http://src_ip:9200/index_name –output=http://dest_ip:9200/index_name –type=data