Ad Widget

Collapse

How to restore a db backup in a docker container?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kiesel
    Junior Member
    • Mar 2019
    • 3

    #1

    How to restore a db backup in a docker container?

    I am moving from an undockerized zabbix installation on one server to a dockerized zabbix installation on one server. To that end I have created a zabbix_dump.sql file that contains the contents of the undockerized zabbix.

    How can I import that dump into the dockerized version?

    This is what my docker-compose.yaml file looks like:

    Code:
    version: '3' 
    
    services:
        zabbix:
            image: zabbix/zabbix-appliance:ubuntu-4.2.4
            hostname: zabbix_myenv
            environment:
                MYHOST: myhost
            volumes:
              - /etc/localtime:/etc/localtime:ro
              - mysql_files:/var/lib/mysql
              - ./backups:/backups
            ports:
              - 580:80                     
    volumes:
        mysql_files:
    I tried two thinks: I changed into running container and imported the backup like any normal mysql backup:

    Code:
    /usr/bin/mysql -u zabbix--password=zabbix < zabbix_dump.sql
    And i ran a mysql container and mounted the volume mysql_files.

    Code:
    docker run -v /home/john/docker/zabbix/zabbix_qa/backups:/etc/backup -v zabbix_qa_mysql_files:/var/lib/mysql mysql
    from where I then ran the same mysql-command.


    Both times zabbix wouldn't start when I ran docker-compose:


    Code:
    ** Deploying Zabbix appliance (nginx) with mysql database
    
    ** Preparing the system
    
    ** Configuring local MySQL server
    
    **** MySQL data directory is not empty. Using already existing installation.
    
    ln: failed to create symbolic link '/run/mysqld/mysqld': File exists
    
    ** Starting MySQL server in background mode
    
    ** Preparing Zabbix server
    
    ********************
    
    * DB_SERVER_HOST: localhost
    
    * DB_SERVER_PORT: 3306
    
    * DB_SERVER_DBNAME: zabbix
    
    * DB_SERVER_ROOT_USER: root
    
    * DB_SERVER_ROOT_PASS:
    
    * DB_SERVER_ZBX_USER: zabbix
    
    * DB_SERVER_ZBX_PASS: zabbix
    
    ********************
    
    mysqladmin: [Warning] Using a password on the command line interface can be insecure.
    
    **** MySQL server is not available. Waiting 5 seconds...
    
    mysqladmin: [Warning] Using a password on the command line interface can be insecure.
    
    **** MySQL server is not available. Waiting 5 seconds...
    The instance never comes up. Any ideas on how to successfully do this?
  • kiesel
    Junior Member
    • Mar 2019
    • 3

    #2
    I tried the following:

    HTML Code:
    catzabbix_dump.sql |docker exec -i 2f3c6722c21e /usr/bin/mysql -u root --password=zabbix zabbix
    and restarted the instance.

    Now I am greeted by:
    • The frontend does not match Zabbix database. Current database version (mandatory/optional): 4010004/4010004. Required mandatory version: 4020000. Contact your system administrator.

    Is there a better method to move a zabbix instance?


    Comment

    Working...