{"id":13340,"date":"2019-04-01T20:50:16","date_gmt":"2019-04-01T20:50:16","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13340"},"modified":"2019-04-01T20:50:16","modified_gmt":"2019-04-01T20:50:16","slug":"how-to-backup-restore-mysql-mariadb-and-postgresql-using-automysqlbackup-and-autopostgresqlbackup-tools","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-backup-restore-mysql-mariadb-and-postgresql-using-automysqlbackup-and-autopostgresqlbackup-tools\/","title":{"rendered":"How to Backup\/Restore MySQL\/MariaDB and PostgreSQL Using \u2018Automysqlbackup\u2019 and \u2018Autopostgresqlbackup\u2019 Tools"},"content":{"rendered":"<p>If you are a database administrator (<strong>DBA<\/strong>) or are responsible for maintaining, backing up, and restoring databases, you know you can\u2019t afford to lose data. The reason is simple: losing data not only means the loss of important information, but also may damage your business financially.<\/p>\n<div id=\"attachment_15605\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/mysql-mariadb-postgresql-database-backup.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15605\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/mysql-mariadb-postgresql-database-backup.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/mysql-mariadb-postgresql-database-backup.png 717w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/mysql-mariadb-postgresql-database-backup-620x297.png 620w\" alt=\"MySQL\/MariaDB &amp; PostgreSQL Backup\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15605\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15605\" class=\"wp-caption-text\">MySQL\/MariaDB &amp; PostgreSQL Backup\/Restore<\/p>\n<\/div>\n<p>For that reason, you must always make sure that:<\/p>\n<p><strong>1.<\/strong>\u00a0your databases are backed up on a periodic basis,<br \/>\n<strong>2.<\/strong>\u00a0those backups are stored in a safe place, and<br \/>\n<strong>3.<\/strong>\u00a0you perform restoration drills regularly.<\/p>\n<p>This last activity should not be overlooked, as you don\u2019t want to run into a major issue without having practiced what needs to be done in such situation.<\/p>\n<p>In this tutorial we will introduce you to two nice utilities to back up\u00a0<strong>MySQL<\/strong>\u00a0\/\u00a0<strong>MariaDB<\/strong>\u00a0and\u00a0<strong>PostgreSQL<\/strong>databases, respectively:\u00a0<strong>automysqlbackup<\/strong>\u00a0and\u00a0<strong>autopostgresqlbackup<\/strong>.<\/p>\n<p>Since the latter is based on the former, we will focus our explanation on\u00a0<strong>automysqlbackup<\/strong>\u00a0and highlight differences with\u00a0<strong>autopgsqlbackup<\/strong>, if any at all.<\/p>\n<p>It is strongly recommended to store the backups in a\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-samba-file-sharing-for-linux-windows-clients\/\" target=\"_blank\" rel=\"noopener\">network share mounted<\/a>\u00a0in the backup directory so that in the event of a system-wide crash, you will still be covered.<\/p>\n<p>Read following useful guides on MySQL:<\/p>\n<div id=\"exam_announcement\"><a href=\"https:\/\/www.tecmint.com\/gliding-through-database-mysql-in-a-nutshell-part-i\/\" target=\"_blank\" rel=\"noopener\">MySQL Basic Database Administration Commands<\/a><\/div>\n<div id=\"exam_announcement\"><a href=\"https:\/\/www.tecmint.com\/mysql-backup-and-restore-commands-for-database-administration\/\" target=\"_blank\" rel=\"noopener\">MySQL Backup and Restore Commands for Database Administration<\/a><\/div>\n<div id=\"exam_announcement\"><a href=\"https:\/\/www.tecmint.com\/phpmybackuppro-a-web-based-mysql-backup-tool-for-linux\/\" target=\"_blank\" rel=\"noopener\">phpMyBackupPro \u2013 A Web Based MySQL Backup Tool<\/a><\/div>\n<div id=\"exam_announcement\"><a href=\"https:\/\/www.tecmint.com\/mysqldumper-a-php-and-perl-based-mysql-database-backup-tool\/\" target=\"_blank\" rel=\"noopener\">MySQLDumper: A PHP and Perl Based MySQL Database Backup Tool<\/a><\/div>\n<div id=\"exam_announcement\"><a href=\"https:\/\/www.tecmint.com\/basic-mysql-interview-questions-for-database-administrators\/\" target=\"_blank\" rel=\"noopener\">15 Basic MySQL Interview Questions for Database Administrators<\/a><\/div>\n<h3>Installing MySQL \/ MariaDB \/ PostgreSQL Databases<\/h3>\n<p><strong>1.<\/strong>\u00a0This guide assumes the you must have\u00a0<strong>MySQL<\/strong>\u00a0\/\u00a0<strong>MariaDB<\/strong>\u00a0\/\u00a0<strong>PostgreSQL<\/strong>\u00a0instance running, If not, please install the following packages:<\/p>\n<h4>Fedora-based distributions:<\/h4>\n<pre># yum update &amp;&amp; yum install mariadb mariadb-server mariadb-libs postgresql postgresql-server postgresql-libs\r\n<\/pre>\n<h4>Debian and derivatives:<\/h4>\n<pre># aptitude update &amp;&amp; aptitude install mariadb-client mariadb-server mariadb-common postgresql-client postgresql postgresql-common\r\n<\/pre>\n<p><strong>2.<\/strong>\u00a0You have a testing\u00a0<strong>MySQL<\/strong>\u00a0\/\u00a0<strong>MariaDB<\/strong>\u00a0\/\u00a0<strong>PostgreSQL<\/strong>\u00a0database that you can use (you are advised to\u00a0<strong>NOT<\/strong>\u00a0use either\u00a0<strong>automysqlbackup<\/strong>\u00a0or\u00a0<strong>autopostgresqlbackup<\/strong>\u00a0in a production environment until you have become acquainted with these tools).<\/p>\n<p>Otherwise, create two sample databases and populate them with data before proceeding. In this article I will use the following databases and tables:<\/p>\n<div class=\"code-label\" title=\"Create MySQL\/MariaDB Database\">MySQL\/MariaDB<\/div>\n<pre>CREATE DATABASE mariadb_db;\r\nCREATE TABLE tecmint_tbl (UserID INT AUTO_INCREMENT PRIMARY KEY, \r\nUserName VARCHAR(50), \r\nIsActive BOOL);\r\n<\/pre>\n<div id=\"attachment_15591\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-MySQL-Database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15591\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-MySQL-Database.png\" alt=\"Create MySQL Database\" width=\"446\" height=\"173\" aria-describedby=\"caption-attachment-15591\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15591\" class=\"wp-caption-text\">Create MySQL Database<\/p>\n<\/div>\n<div class=\"code-label\" title=\"Create PostgreSQL Database\">PostgreSQL<\/div>\n<pre>CREATE DATABASE postgresql_db;\r\nCREATE TABLE tecmint_tbl (\r\nUserID SERIAL PRIMARY KEY,\r\nUserName VARCHAR(50),\r\nIsActive BOOLEAN);\r\n<\/pre>\n<div id=\"attachment_15592\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-PostgreSQL-Database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-15592\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Create-PostgreSQL-Database.png\" alt=\"Create PostgreSQL Database\" width=\"358\" height=\"135\" aria-describedby=\"caption-attachment-15592\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15592\" class=\"wp-caption-text\">Create PostgreSQL Database<\/p>\n<\/div>\n<h3>Installing automysqlbackup and autopgsqlbackup in CentOS 7 and Debian 8<\/h3>\n<p><strong>3.<\/strong>\u00a0In\u00a0<strong>Debian 8<\/strong>, both tools are available in the repositories, so installing them is as simple as running:<\/p>\n<pre># aptitude install automysqlbackup autopostgresqlbackup\r\n<\/pre>\n<p>Whereas in\u00a0<strong>CentOS 7<\/strong>\u00a0you will need to download the installation scripts and run them. In the sections below we will focus exclusively on installing, configuring, and testing these tools on\u00a0<strong>CentOS 7<\/strong>\u00a0since for\u00a0<strong>Debian 8<\/strong>\u00a0\u2013 where they almost work out of the box, we will make the necessary clarifications later in this article.<\/p>\n<h4>Installing and configuring automysqlbackup in CentOS 7<\/h4>\n<p><strong>4.<\/strong>\u00a0Let us begin by creating a working directory inside\u00a0<code>\/opt<\/code>\u00a0to download the installation script and run it:<\/p>\n<pre># mkdir \/opt\/automysqlbackup\r\n# cd \/opt\/automysqlbackup\r\n# wget http:\/\/ufpr.dl.sourceforge.net\/project\/automysqlbackup\/AutoMySQLBackup\/AutoMySQLBackup%20VER%203.0\/automysqlbackup-v3.0_rc6.tar.gz\r\n# tar zxf automysqlbackup-v3.0_rc6.tar.gz\r\n# .\/install.sh\r\n<\/pre>\n<p>.<\/p>\n<div id=\"attachment_15594\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Installing-AutoMysqlBackup-in-CentOS-7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15594\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Installing-AutoMysqlBackup-in-CentOS-7-620x369.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Installing-AutoMysqlBackup-in-CentOS-7-620x369.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Installing-AutoMysqlBackup-in-CentOS-7.png 787w\" alt=\"Installing AutoMysqlBackup in CentOS-7\" width=\"620\" height=\"369\" aria-describedby=\"caption-attachment-15594\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15594\" class=\"wp-caption-text\">Installing AutoMysqlBackup in CentOS-7<\/p>\n<\/div>\n<p><strong>5.<\/strong>\u00a0The configuration file for\u00a0<strong>automysqlbackup<\/strong>\u00a0is located inside\u00a0<strong>\/etc\/automysqlbackup<\/strong>\u00a0under the name\u00a0<strong>myserver.conf<\/strong>. Let\u2019s take a look at most relevant configuration directives:<\/p>\n<div class=\"code-label\" title=\"Configure automysqlbackup\">myserver.conf \u2013 Configure Automysqlbackup<\/div>\n<pre># Username to access the MySQL server\r\nCONFIG_mysql_dump_username='<strong>root<\/strong>'\r\n# Password\r\nCONFIG_mysql_dump_password='<strong>YourPasswordHere<\/strong>'\r\n# Host name (or IP address) of MySQL server\r\nCONFIG_mysql_dump_host='<strong>localhost<\/strong>'\r\n# Backup directory\r\nCONFIG_backup_dir='<strong>\/var\/backup\/db\/automysqlbackup<\/strong>'\r\n# List of databases for Daily\/Weekly Backup e.g. ( 'DB1' 'DB2' 'DB3' ... )\r\n# set to (), i.e. empty, if you want to backup all databases\r\nCONFIG_db_names=(<strong>AddYourDatabase Names Here<\/strong>)\r\n# List of databases for Monthly Backups.\r\n# set to (), i.e. empty, if you want to backup all databases\r\nCONFIG_db_month_names=(<strong>AddYourDatabase Names Here<\/strong>)\r\n# Which day do you want monthly backups? (01 to 31)\r\n# If the chosen day is greater than the last day of the month, it will be done\r\n# on the last day of the month.\r\n# Set to 0 to disable monthly backups.\r\nCONFIG_do_monthly=\"<strong>01<\/strong>\"\r\n# Which day do you want weekly backups? (1 to 7 where 1 is Monday)\r\n# Set to 0 to disable weekly backups.\r\nCONFIG_do_weekly=\"<strong>5<\/strong>\"\r\n# Set rotation of daily backups. VALUE*24hours\r\n# If you want to keep only today's backups, you could choose 1, i.e. everything older than 24hours will be removed.\r\nCONFIG_rotation_daily=<strong>6<\/strong>\r\n# Set rotation for weekly backups. VALUE*24hours. A value of 35 means 5 weeks.\r\nCONFIG_rotation_weekly=<strong>35<\/strong>\r\n# Set rotation for monthly backups. VALUE*24hours. A value of 150 means 5 months.\r\nCONFIG_rotation_monthly=<strong>150<\/strong>\r\n# Include CREATE DATABASE statement in backup?\r\nCONFIG_mysql_dump_create_database=<strong>'no'<\/strong>\r\n# Separate backup directory and file for each DB? (yes or no)\r\nCONFIG_mysql_dump_use_separate_dirs=<strong>'yes'<\/strong>\r\n# Choose Compression type. (gzip or bzip2)\r\nCONFIG_mysql_dump_compression=<strong>'gzip'<\/strong>\r\n# What would you like to be mailed to you?\r\n# - log   : send only log file\r\n# - files : send log file and sql files as attachments (see docs)\r\n# - stdout : will simply output the log to the screen if run manually.\r\n# - quiet : Only send logs if an error occurs to the MAILADDR.\r\nCONFIG_mailcontent=<strong>'quiet'<\/strong>\r\n# Email Address to send mail to? (user@domain.com)\r\nCONFIG_mail_address=<strong>'root'<\/strong>\r\n# Do you wish to encrypt your backups using openssl?\r\n#CONFIG_encrypt='no'\r\n# Choose a password to encrypt the backups.\r\n#CONFIG_encrypt_password='password0123'\r\n# Command to run before backups (uncomment to use)\r\n#CONFIG_prebackup=\"\/etc\/mysql-backup-pre\"\r\n# Command run after backups (uncomment to use)\r\n#CONFIG_postbackup=\"\/etc\/mysql-backup-post\"\r\n<\/pre>\n<p>Once you have configured\u00a0<strong>automysqlbackup<\/strong>\u00a0as per your needs, you are strongly advise to check out the\u00a0<strong>README<\/strong>\u00a0file found in\u00a0<strong>\/etc\/automysqlbackup\/README<\/strong>.<\/p>\n<h4>MySQL Database Backup<\/h4>\n<p><strong>6.<\/strong>\u00a0When you\u2019re ready, go ahead and run the program, passing the configuration file as argument:<\/p>\n<pre># automysqlbackup \/etc\/automysqlbackup\/myserver.conf\r\n<\/pre>\n<div id=\"attachment_15595\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Configure-automysqlbackup.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15595\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Configure-automysqlbackup-620x147.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Configure-automysqlbackup-620x147.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Configure-automysqlbackup.png 786w\" alt=\"Configure Automysqlbackup on CentOS 7\" width=\"620\" height=\"147\" aria-describedby=\"caption-attachment-15595\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15595\" class=\"wp-caption-text\">Configure Automysqlbackup on CentOS 7<\/p>\n<\/div>\n<p>A quick inspection of the\u00a0<strong>daily<\/strong>\u00a0directory will show that\u00a0<strong>automysqlbackup<\/strong>\u00a0has run successfully:<\/p>\n<pre># pwd\r\n# ls -lR daily\r\n<\/pre>\n<div id=\"attachment_15596\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/MySQL-Daily-Database-Backup.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15596\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/MySQL-Daily-Database-Backup-620x324.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/MySQL-Daily-Database-Backup-620x324.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/MySQL-Daily-Database-Backup.png 816w\" alt=\"MySQL Daily Database Backup\" width=\"620\" height=\"324\" aria-describedby=\"caption-attachment-15596\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15596\" class=\"wp-caption-text\">MySQL Daily Database Backup<\/p>\n<\/div>\n<p>Of course you can add a crontab entry to run\u00a0<strong>automysqlbackup<\/strong>\u00a0at a time of day that best suits your needs (<strong>1:30<\/strong>am every day in the below example):<\/p>\n<pre>30 01 * * * \/usr\/local\/bin\/automysqlbackup \/etc\/automysqlbackup\/myserver.conf\r\n<\/pre>\n<h4>Restoring a MySQL Backup<\/h4>\n<p><strong>7.<\/strong>\u00a0Now let\u2019s drop the\u00a0<strong>mariadb_db<\/strong>\u00a0database on purpose:<\/p>\n<div id=\"attachment_15597\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Drop-MySQL-Database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15597\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Drop-MySQL-Database-620x404.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Drop-MySQL-Database-620x404.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Drop-MySQL-Database.png 722w\" alt=\"Drop MariaDB Database\" width=\"620\" height=\"404\" aria-describedby=\"caption-attachment-15597\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15597\" class=\"wp-caption-text\">Drop MariaDB Database<\/p>\n<\/div>\n<p>Let\u2019s create it again and restore the backup. In the MariaDB prompt, type:<\/p>\n<pre>CREATE DATABASE mariadb_db;\r\nexit\r\n<\/pre>\n<p>Then locate:<\/p>\n<pre># cd \/var\/backup\/db\/automysqlbackup\/daily\/mariadb_db\r\n# ls\r\n<\/pre>\n<div id=\"attachment_15598\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Locate-MariaDB-Database-backup.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15598\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Locate-MariaDB-Database-backup-620x105.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Locate-MariaDB-Database-backup-620x105.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Locate-MariaDB-Database-backup.png 725w\" alt=\"Locate MariaDB Database backup\" width=\"620\" height=\"105\" aria-describedby=\"caption-attachment-15598\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15598\" class=\"wp-caption-text\">Locate MariaDB Database backup<\/p>\n<\/div>\n<p>And restore the backup:<\/p>\n<pre># mysql -u root -p mariadb_db &lt; daily_mariadb_db_2015-09-01_23h19m_Tuesday.sql\r\n# mysql -u root -p\r\nMariaDB [(none)]&gt; USE mariadb_db; \r\nMariaDB [(none)]&gt; SELECT * FROM tecmint_tb1;\r\n<\/pre>\n<div id=\"attachment_15599\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Restore-MariaDB-Backup.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15599\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Restore-MariaDB-Backup-620x350.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Restore-MariaDB-Backup-620x350.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/Restore-MariaDB-Backup.png 907w\" alt=\"Restore MariaDB Backup\" width=\"620\" height=\"350\" aria-describedby=\"caption-attachment-15599\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15599\" class=\"wp-caption-text\">Restore MariaDB Backup<\/p>\n<\/div>\n<h3>Installing and configuring autopostgresqlbackup in CentOS 7<\/h3>\n<p><strong>8.<\/strong>\u00a0In order for\u00a0<strong>autopostgresql<\/strong>\u00a0to work flawlessly in\u00a0<strong>CentOS 7<\/strong>, we will need to install some dependencies first:<\/p>\n<pre># yum install mutt sendmail\r\n<\/pre>\n<p>Then let&#8217;s repeat the process as before:<\/p>\n<pre># mkdir \/opt\/autopostgresqlbackup\r\n# cd \/opt\/autopostgresqlbackup\r\n# wget http:\/\/ufpr.dl.sourceforge.net\/project\/autopgsqlbackup\/AutoPostgreSQLBackup\/AutoPostgreSQLBackup-1.0\/autopostgresqlbackup.sh.1.0\r\n# mv autopostgresqlbackup.sh.1.0 \/opt\/autopostgresqlbackup\/autopostgresqlbackup.sh\r\n<\/pre>\n<p>Let&#8217;s make the script executable and\u00a0<strong>start<\/strong>\u00a0\/\u00a0<strong>enable<\/strong>\u00a0the service:<\/p>\n<pre># chmod 755 autopostgresqlbackup.sh\r\n# systemctl start postgresql\r\n# systemctl enable postgresql\r\n<\/pre>\n<p>Finally, we will edit the value of the backup directory setting to:<\/p>\n<div class=\"code-label\" title=\"Configure Autopostgresqlbackup\">autopostgresqlbackup.sh &#8211; Configure Autopostgresqlbackup<\/div>\n<pre>BACKUPDIR=\"\/var\/backup\/db\/autopostgresqlbackup\"\r\n<\/pre>\n<p>After having through the configuration file of\u00a0<strong>automysqlbackup<\/strong>, configuring this tool is very easy (that part of the task is left up to you).<\/p>\n<p><strong>9.<\/strong>\u00a0In\u00a0<strong>CentOS 7<\/strong>, as opposed to\u00a0<strong>Debian 8<\/strong>,\u00a0<strong>autopostgresqlbackup<\/strong>\u00a0is best run as the\u00a0<strong>postgres<\/strong>\u00a0system user, so in order to do that you should either switch to that account or add a cron job to its crontab file:<\/p>\n<pre># crontab -u postgres -e\r\n<\/pre>\n<pre>30 01 * * * \/opt\/autopostgresqlbackup\/autopostgresqlbackup.sh\r\n<\/pre>\n<p>The backup directory, by the way, needs to be created and its permissions and group ownership must be set recursively to\u00a0<strong>0770<\/strong>\u00a0and\u00a0<strong>postgres<\/strong>\u00a0(again, this will NOT be necessary in\u00a0<strong>Debian<\/strong>):<\/p>\n<pre># mkdir \/var\/backup\/db\/autopostgresqlbackup\r\n# chmod -R 0770 \/var\/backup\/db\/autopostgresqlbackup\r\n# chgrp -R postgres \/var\/backup\/db\/autopostgresqlbackup\r\n<\/pre>\n<p>The result:<\/p>\n<pre># cd \/var\/backup\/db\/autopostgresqlbackup\r\n# pwd\r\n# ls -lR daily\r\n<\/pre>\n<div id=\"attachment_15601\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/PostgreSQL-Daily-Database-Backup.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15601\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/PostgreSQL-Daily-Database-Backup-620x330.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/PostgreSQL-Daily-Database-Backup-620x330.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/09\/PostgreSQL-Daily-Database-Backup.png 815w\" alt=\"PostgreSQL Daily Database Backup\" width=\"620\" height=\"330\" aria-describedby=\"caption-attachment-15601\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15601\" class=\"wp-caption-text\">PostgreSQL Daily Database Backup<\/p>\n<\/div>\n<p><strong>10.<\/strong>\u00a0Now you can restore the files when needed (remember to do this as user postgres after recreating the empty database):<\/p>\n<pre># gunzip -c postgresql_db_2015-09-02.Wednesday.sql.gz | psql postgresql_db\r\n<\/pre>\n<h3>Considerations in Debian 8<\/h3>\n<p>As we mentioned earlier, not only the installation of these tools in\u00a0<strong>Debian<\/strong>\u00a0is more straightforward, but also their respective configurations. You will find the configuration files in:<\/p>\n<ol>\n<li><strong>Automysqlbackup<\/strong>: \/etc\/default\/automysqlbackup<\/li>\n<li><strong>Autopostgresqlbackup<\/strong>: \/etc\/default\/autopostgresqlbackup<\/li>\n<\/ol>\n<h3>Summary<\/h3>\n<p>In this article we have explained how to install and use\u00a0<strong>automysqlbackup<\/strong>\u00a0and\u00a0<strong>autopostgresqlbackup<\/strong>\u00a0(learning how to use the first will help you master the second as well), two great database back up tools that can make your tasks as a DBA or system administrator \/ engineer much easier.<\/p>\n<p>Please note that you can expand on this topic by setting up\u00a0<strong>email notifications<\/strong>\u00a0or sending backup files as attachments via email \u2013 not strictly required, but may come in handy sometimes.<\/p>\n<p>As a final note, remember that the permissions of configuration files should be set to the minimum (<strong>0600<\/strong>\u00a0in most cases). We look forward to hearing what you think about this article. Feel free to drop us a note using the form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/mysql-mariadb-postgresql-database-backup-using-automysqlbackup-autopostgresqlbackup\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are a database administrator (DBA) or are responsible for maintaining, backing up, and restoring databases, you know you can\u2019t afford to lose data. The reason is simple: losing data not only means the loss of important information, but also may damage your business financially. MySQL\/MariaDB &amp; PostgreSQL Backup\/Restore For that reason, you must &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-backup-restore-mysql-mariadb-and-postgresql-using-automysqlbackup-and-autopostgresqlbackup-tools\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Backup\/Restore MySQL\/MariaDB and PostgreSQL Using \u2018Automysqlbackup\u2019 and \u2018Autopostgresqlbackup\u2019 Tools&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13340","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13340"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13340\/revisions"}],"predecessor-version":[{"id":13341,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13340\/revisions\/13341"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}