{"id":16596,"date":"2017-10-02T14:39:18","date_gmt":"2017-10-02T14:39:18","guid":{"rendered":"https:\/\/www.mautic.org\/backup-mautic-database-in-dropbox\/"},"modified":"2024-12-18T11:49:41","modified_gmt":"2024-12-18T11:49:41","slug":"backup-mautic-database-in-dropbox","status":"publish","type":"post","link":"https:\/\/mautic.org\/blog\/backup-mautic-database-in-dropbox","title":{"rendered":"Backup Mautic Database in Dropbox"},"content":{"rendered":"<p><em>We&#8217;re excited to continue sharing content developed by the Mautic community. This solution and post was developed and written by Joan Nin (Slack: @ninjoan).<\/em><\/p>\n<p>Are you looking for ways to make a backup of your Mautic instance fast, easy and automatic? This tutorial will give you the ability to backup your Mautic database to your Dropbox account.<\/p>\n<p>You will need the following:<\/p>\n<ol>\n<li>Dropbox account<\/li>\n<li>Backup script<\/li>\n<li>Cron job<\/li>\n<li>Basic knowledge of the command line (PC) or terminal (Mac)<\/li>\n<\/ol>\n<h3>Step 1: Dropbox Account<\/h3>\n<p>Sign-in or create a brand new account with Dropbox then go to <a href=\"https:\/\/www.dropbox.com\/developers\/apps\" target=\"_blank\" rel=\"noopener\">https:\/\/www.dropbox.com\/developers\/apps<\/a> on your web browser, and create a new Dropbox app. Fill in the information of the new app as shown below, and enter the app name use a name that will be easy to you to remember in case you have more apps.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\" size-full wp-image-14689\" src=\"https:\/\/www.mautic.org\/wp-content\/uploads\/2017\/10\/UGC-Post-Backups-2-1024x959_12.jpg\" alt=\"UGC-Post-Backups-2-1024x959\" title=\"UGC-Post-Backups-2-1024x959\" width=\"1024\" height=\"959\" srcset=\"https:\/\/mautic.org\/wp-content\/uploads\/2017\/10\/UGC-Post-Backups-2-1024x959_12.jpg 1024w, https:\/\/mautic.org\/wp-content\/uploads\/2017\/10\/UGC-Post-Backups-2-1024x959_12-300x281.jpg 300w, https:\/\/mautic.org\/wp-content\/uploads\/2017\/10\/UGC-Post-Backups-2-1024x959_12-768x719.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>After you have created a new app, you will redirect to new windows and you will see a button with the text Generated access token click and copy the access token.<\/p>\n<p><img decoding=\"async\" class=\" size-full wp-image-14690\" src=\"https:\/\/www.mautic.org\/wp-content\/uploads\/2017\/10\/UGC-Post-Backups-3-1003x1024_12.jpg\" alt=\"UGC-Post-Backups-3-1003x1024\" title=\"UGC-Post-Backups-3-1003x1024\" width=\"1003\" height=\"1024\" srcset=\"https:\/\/mautic.org\/wp-content\/uploads\/2017\/10\/UGC-Post-Backups-3-1003x1024_12.jpg 1003w, https:\/\/mautic.org\/wp-content\/uploads\/2017\/10\/UGC-Post-Backups-3-1003x1024_12-294x300.jpg 294w, https:\/\/mautic.org\/wp-content\/uploads\/2017\/10\/UGC-Post-Backups-3-1003x1024_12-768x784.jpg 768w\" sizes=\"(max-width: 1003px) 100vw, 1003px\" \/><\/p>\n<h3>Step 2: Backup Script<\/h3>\n<p>The script we going to use is made by <a href=\"https:\/\/github.com\/andreafabrizi\/Dropbox-Uploader\" target=\"_blank\" rel=\"noopener\">Andrea Fabrizi<\/a> kudos to this guy. To use Dropbox backup script, <a href=\"https:\/\/github.com\/andreafabrizi\/Dropbox-Uploader\" target=\"_blank\" rel=\"noopener\">download<\/a> the script and make it executable.<\/p>\n<pre>wget https:\/\/raw.github.com\/andreafabrizi\/Dropbox-Uploader\/master\/dropbox_uploader.sh\nchmod +x dropbox_uploader.sh<\/pre>\n<p>Then run the following command;<\/p>\n<pre>.\/dropbox_uploder.sh<\/pre>\n<p>Next it will ask you to insert the generated access token. Insert the provided token and confirm. To verify that you have established the connection with Dropbox, run the following command;<\/p>\n<pre>.\/dropbox_uploder.sh info<\/pre>\n<p>Doing so should display your Dropbox Information;<\/p>\n<pre>Dropbox Uploader v1.0\n> Getting info... \nName:\t\tJoan Nin\nUID:\t\tdbid:XXXXXXXXXXXXXXXXXXXXXXX\nEmail:\t\tyour-email\nCountry:\tDO\n<\/pre>\n<p>Now let&#8217;s create a shell script that will make the import of our database.<\/p>\n<p>Create a new directory db-backup and a .sh file.<\/p>\n<pre>cd\nmkdir db-backup\nnano  dbdump.sh<\/pre>\n<p>And copy and paste this info to the dbdump.sh file you create.<\/p>\n<pre>#!\/bin\/bash\nsudo mysqldump -u<em>MYSQLUSER<\/em> -p<em>MYSQLDATABASE-PASSWORD<\/em> <em>DATABASENAME<\/em> > \n\/root\/db-backup\/mautic.sql\n## THIS LINE UPLOADS THE MAUTIC.SQL FILE TO THE DROPBOX DIRECTORY BACKUP-Mautic\n.\/dropbox_uploader.sh upload \/root\/db-backup\/mautic.sql \/BACKUP-Mautic\n## Removed THIS WILL REMOVE THE MAUTIC.SQL FROM YOUR SERVER\nrm -r \/root\/db-backup\/mautic.sql\n#END<\/pre>\n<p><strong>NOTE:<\/strong> Replace the italics text with your information.<br \/>\n<em>MYSQLUSER<\/em> = sql user<br \/>\n<em>MYSQLDATABASE-PASSWORD<\/em> = SQL Password<br \/>\n<em>DATABASENAME<\/em> = the name of the database you use in Mautic<\/p>\n<h3>Step 3: Cron Job<\/h3>\n<p>Now create a cron job that will automate this task for you. Using the crontab from your server create the following line;<\/p>\n<pre>### MAUTIC BACKUP\n27 3 *\/15 * * echo \"`date -u` `\/root\/db-backup\/dbdump.sh`\" >> \/root\/db-backup\/status.log 2>&1<\/pre>\n<p>This line will run the backup \u201cAt 03:27 on every 15th day-of-month.\u201d you can replace the with the time you prefer. Also this will create a log file with the date that the cron job will run. I think this is a pretty neat option for backup\/audit.<\/p>\n<p>And that&#8217;s it. A simple, yet effective way to backup your Mautic instance.<\/p>\n<p>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><\/p>\n<p>We want to thank our community for offering insight into how they work with Mautic. Do you have a different process for backing up your Mautic instance? Comment below and let us know!<\/p>\n<p>Also, if you&#8217;re interested, here&#8217;s a quick tutorial video on using CPanel to add a cron job.<\/p>\n<p><iframe width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\" consent-original-src-_=\"https:\/\/www.youtube.com\/embed\/Jw8940xZxPM?rel=0\" consent-required=\"21100\" consent-by=\"services\" consent-id=\"21101\" consent-click-original-src-_=\"https:\/\/www.youtube.com\/embed\/Jw8940xZxPM?rel=0&amp;autoplay=1\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you looking for ways to make a backup of your Mautic instance fast, easy and automatic? This tutorial will give you the ability to backup Mautic.<\/p>\n","protected":false},"author":50,"featured_media":15993,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"publish_to_discourse":"","publish_post_category":"","wpdc_auto_publish_overridden":"","wpdc_topic_tags":"","wpdc_pin_topic":"","wpdc_pin_until":"","discourse_post_id":"","discourse_permalink":"","wpdc_publishing_response":"","wpdc_publishing_error":"","footnotes":""},"categories":[1495],"tags":[760,841,866,966,1077,1150],"class_list":["post-16596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-for-integrators","tag-backup","tag-database","tag-dropbox","tag-instance","tag-mautic","tag-php"],"acf":[],"_links":{"self":[{"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/posts\/16596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/comments?post=16596"}],"version-history":[{"count":1,"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/posts\/16596\/revisions"}],"predecessor-version":[{"id":17060,"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/posts\/16596\/revisions\/17060"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/media\/15993"}],"wp:attachment":[{"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/media?parent=16596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/categories?post=16596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mautic.org\/wp-json\/wp\/v2\/tags?post=16596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}