Create Encrypted WordPress MySQL Backup without any DB details, just the wp-config.php

eval $(sed -n "s/^d[^D]*DB_\([NUPH]\)[ASO].*',[^']*'\([^']*\)'.*/_\1='\2'/p" wp-config.php) && mysqldump --opt --add-drop-table -u$_U -p$_P -h$_H $_N | gpg -er AskApache >`date +%m%d%y-%H%M.$_N.sqls`
The coolest way I've found to backup a wordpress mysql database using encryption, and using local variables created directly from the wp-config.php file so that you don't have to type them- which would allow someone sniffing your terminal or viewing your shell history to see your info. I use a variation of this for my servers that have hundreds of wordpress installs and databases by using a find command for the wp-config.php file and passing that through xargs to my function.
Sample Output
gpg: using PGP trust model
gpg: using subkey 8B2 instead of primary key 6B40
gpg: This key belongs to us
gpg: reading from `[stdin]'
gpg: writing to stdout
gpg: ELG-E/AES256 encrypted for: "82 AskApache <>"


What Others Think

That's great! Thanks for sharing this command. I am a student of software engineering and computer science, recently I have found this Quize Plugin WordPress plugin tool for increasing page views and at the same time ads revenue from website! This command is so inspirational for me practicing as my academic homework.
Davidmal · 69 weeks and 4 days ago
This command is not working in my Linux. Is their any problem? Actually, I have been using this Wordpress Hosting. Help me with this?
ChelseaSCripe · 42 weeks and 5 days ago
I am glad that this way of transferring technical knowledge has been used by the company. I never new about how cloud works but I thank best wordpress hosting for beginners who have posted something unique and interesting. More unique items should be brought in the industry.
WalkerNolan · 11 weeks and 4 days ago
is this site created using Wordpress or not?
ofoghweb · 11 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: