数据库命令 之 备份

目录

  • MySQL

  • Mongo

  • Redis

  • Elasticsearch

MySQL

# 导出
mysqldump -u"$user" -p"$passwd" db_name > ~/backup/db_name.sql

# 拷贝
scp [email protected]:/home/user/backup/db_name.sql ~/Downloads

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

Mongo

# 导出
mongodump -h 127.0.0.1:27017 –authenticationDatabase admin -u user -p password -d logs -o ~/backup/

# 拷贝
scp -r [email protected]:/home/user/backup/logs ~/Downloads

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

Redis

# 安装
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

# 安装
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

你可能感兴趣的:(数据库命令 之 备份)