0%

how to backup mysql database and upload to dropbox

in this post, I will show you how to backup MySQL database in docker and upload it to Dropbox.

install dropbox on Linux

we can install Dropbox through the command below:

# 32bit
$ cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf -

# 64 bit

$ cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -

then you can type the command ~/.dropbox-dist/dropboxd to install dropbox.

but when I type dropboxd command, the error showed.

Traceback (most recent call last):
  File "dropbox/client/main.pyc", line 254, in <module>
  File "dropbox/foundation/navigation_service/factory.pyc", line 22, in <module>
  File "dropbox/foundation/navigation_service/navigation_service_impl.pyc", line 57, in <module>
  File "dropbox/foundation/html_views/electron/manager_factory.pyc", line 14, in <module>
  File "dropbox/foundation/html_views/local/common/manager.pyc", line 33, in <module>
  File "dropbox/client/features/model_registry.pyc", line 13, in <module>
  File "dropbox/client/features/generated_models.pyc", line 292, in <module>
  File "dropbox/client/features/previews/view_anchor.pyc", line 106, in <module>
  File "<_bootstrap_overrides>", line 153, in load_module
ImportError: libglapi.so.0: cannot open shared object file: No such file or directory
!! dropbox: fatal python exception:
['Traceback (most recent call last):\n', '  File "dropbox/client/main.pyc", line 254, in <module>\n', '  File "dropbox/foundation/navigation_service/factory.pyc", line 22, in <module>\n', '  File "dropbox/foundation/navigation_service/navigation_service_impl.pyc", line 57, in <module>\n', '  File "dropbox/foundation/html_views/electron/manager_factory.pyc", line 14, in <module>\n', '  File "dropbox/foundation/html_views/local/common/manager.pyc", line 33, in <module>\n', '  File "dropbox/client/features/model_registry.pyc", line 13, in <module>\n', '  File "dropbox/client/features/generated_models.pyc", line 292, in <module>\n', '  File "dropbox/client/features/previews/view_anchor.pyc", line 106, in <module>\n', '  File "<_bootstrap_overrides>", line 153, in load_module\n', 'ImportError: libglapi.so.0: cannot open shared object file: No such file or directory\n'] (error 3)
Aborted (core dumped)

the reason is that we are missing some extensions, probably are these below:

sudo apt-get install libc6
sudo apt-get install libglapi-mesa
sudo apt-get install libxdamage1
sudo apt-get install libxfixes3
sudo apt-get install libxcb-glx0
sudo apt-get install libxcb-dri2-0
sudo apt-get install libxcb-dri3-0
sudo apt-get install libxcb-present0
sudo apt-get install libxcb-sync1
sudo apt-get install libxshmfence1
sudo apt-get install libxxf86vm1

after that, we should also make sure of the following:

sudo chown "$USER" "$HOME"
sudo chown -R "$USER" ~/Dropbox ~/.dropbox
sudo chattr -R -i ~/Dropbox
sudo chmod -R u+rw ~/Dropbox ~/.dropbox

this time we can successfully run the command ~/.dropbox-dist/dropboxd. when we first run this command the output will show us an HTML link to request a link to our Dropbox account. after that, we have successfully installed Dropbox on Linux.

Last, we can download the official python dropbox.py to control dropbox. available commands are

$ python3 dropbox.py
Dropbox command-line interface

commands:

Note: use dropbox help <command> to view usage for a specific command.

 autostart    automatically start Dropbox at login
 exclude      ignores/excludes a directory from syncing
 filestatus   get current sync status of one or more files
 help         provide help
 lansync      enables or disables LAN sync
 ls           list directory contents with current sync status
 proxy        set proxy settings for Dropbox
 puburl       get public url of a file in your Dropbox's public folder
 running      return whether Dropbox is running
 sharelink    get a shared link for a file in your Dropbox
 start        start dropboxd
 status       get current status of the dropboxd
 stop         stop dropboxd
 throttle     set bandwidth limits for Dropbox
 update       download latest version of Dropbox
 version      print version information for Dropbox

backup MySQL database

backup MySQL data from docker is very simple.

# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > ~/Dropbox/backup.sql

# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE

conclusion

firstly, we installed Dropbox to our Linux system. then, we use the docker command to dump our backup file to the ~/Dropbox directory so that Dropbox can automatically upload to the Cloud server.

references

欢迎关注我的其它发布渠道