データベースコマンドのバックアップ

1257 ワード

目次

  • 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