You can use plugins such as BackupBuddy, but I prefer to script this and use wp-cli, which reads wp-config.php and means you don’t have to worry about mysql credentials.
wp-cli allows you to:
- export the db:
wp db export <filename>
- import the db:
wp db import <filename>
- safe search and replace (including serialised data):
wp search-replace <search-string> <replace-string>
So, I have a script that
- executes
wp export
on a remote server via ssh - copies the sql export file via scp to my local machine
- executes
wp import
locally - executes
wp search-replace
You could then add it to cron, but I prefer to run it manually – takes less than a minute to sync db from production to my local environment.
Related Posts:
- Why are no posts showing despite my apparently correct DB restoration?
- What happens if I overwrite the current wp_options table with a backup from a week ago?
- WPCLI search and replace in a particlar site dir effect another site-dir
- Rename a table in MySQL
- How should I tackle –secure-file-priv in MySQL?
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- phpMyAdmin – Error > Incorrect format parameter?
- MySQL Database User: Which Privileges are needed?
- Why is my database import losing text widget data?
- Checking if Database Table exists
- How to fetch Data in WordPress using MySQLi or $wpdb
- Connect to database using wordpress wp-config file
- Reset Post IDs to less than 64bit integer
- How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?
- WordPress database scalability from the code perspective
- How to define composite keys with dbDelta()
- Does wpdb add considerable overhead on queries with large result sets?
- Is it possible to define two databases for one installation?
- Does WordPress use the InnoDB engine for MySQL by default?
- Can I use MariaDB instead of MySQL in wordpress?
- Split WP install between 2 databases?
- Inserting Post Meta From SQL
- Faulty restore of the database, encoding issue
- Is altering a default WordPress database table update safe?
- Huge wp_options table
- “MySQL server has gone away” since update to 3.8
- Custom DB_COLLATE (collation) value not working on fresh install?
- Can I transfer a mysql database to another site?
- Size article thumbnails and retrieve them directly from database
- WordPress site uses MyISAM, should I switch to InnoDB necessary?
- Emojis getting converted to “?”
- Which is more efficient? Using usermeta, or creating a new MySQL table?
- For WordPress is there content in the database which I can safely ignore?
- WordPress mysql table double prefixes
- WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
- WordPress database import: Row size too large
- Advanced SELECT query with condtional statements
- Why do mass updates to post_content shows in front end, but not in edit screen?
- Error establishing database connection – high traffic?
- Handling large N data in WordPress
- Improve performance by removing unnecessary database queries
- Redirecting to old domain after migration website
- A MySQL DB within a MySQL DB
- Switching Databases in LocalHost
- WordPress Backend HA (Automatic failover)
- Create table from array with prepare
- Is there a way to recover the table wp_term_relationships?
- Trouble Migrating all data blog from WordPress.com to WordPress.org
- Unable to set a default serialized array using dbdelta()
- How to prevent/delay MySQL connections when an object cache is used?
- Error establishing a database connection,
- Can’t update WordFence Options, clear data manually
- How To Run A Temporary Instance Of a WordPress Backup Without a Database?
- Changing between Local Host DB to Production DB and in reverse
- How to backup my site and restore my wordpress site
- How and where is wordpress adding mySQL content to database?
- restore a db after bad backup
- Why does changing Database Table Prefixes result in loss of content?
- Query Column of Specific ID from Database Table
- How to create more than one new wpdb object?
- Moving WordPress site to new domain – database import [duplicate]
- How to connect and insert data in database of wordpress?
- Buddypress avatar image in database [closed]
- $wpdb->get_var – What value is returned when zero records are found?
- Remote database -> massive response time increase?
- Installing local to live WP into subdirectory
- Getting “Error Establishing a Database Connection” on localhost in new Mac OSX Lion environment
- Cloning blog to localhost via WAMP
- Only allow user to access a link once a year, based on their joining date
- Counting post and changing roles in mysql database. Query not code
- MSQL database wp_postmeta has meta key tve_revision
- I imported an restore an database and It shows #1067 – Invalid default value for ‘user_registered’
- How to edit custom table data in frontend
- local wordpress broke after changing URL
- “BS_” rows in postmeta table
- How do you enable scripts on a WordPress installation in Softaculous?
- is it possible to install new WordPress in an old WordPress folder?
- Is it possible to separate databases in WordPress site – one for orders and the other for all non-orders related
- Exporting Post ID, Post Title, Primary Category and Primary Category ID
- How to create index (sql) to a meta_key?
- Delete all users meta that named: user_avatar
- mySQL database size large, but tables size less
- How do I find out from my database what version of WordPress I need?
- After renaming MySQL database, I can no longer access my Blog page
- How To connect to the same WordPress database with different database user
- Possible to restore wordpress database from mysql56 and sqlite files?
- Hang Up Followed By Can’t select database
- Copy WordPress to new directory
- Create a new table on the database and save parameters from a contact form
- version control for wordpress? (wordpress folder and database at same time)
- Why is converting my database to UTF-8 truncating entries?
- Widgets with *internal* links do not display after database migration
- Merging versions of wp_posts based on post_title
- How to back-up a database on IIS
- export individual posts to text files or a single csv file
- Importing Concrete5 content to WordPress
- WordPress database connection failed, while mysql client is working [closed]
- Uploading to WordPress Database
- Have WordPress Use a Different Database for users