Blog by Daniel Hauck. Sysadmin, Developer, Blogger.

TAG: script

Simple WordPress Bash Backup Script

Hey Guys,

I needed to do some backups of multiple wordpress sites, so I decided to write a backup script especially for wordpress.

All you need is to call the script with two parametes, the first is the folder where your wordpress instance is installed, in my case /var/www/
The second is the folder where to backup it.

So for example:
./backup_wordpress /var/www/ /tmp/backup/

That’s all, the script figures out how to connect to the database, creates a gzipped dump with timestamp, and creates a tar archive also with a timestamp.

You’ll find it in your specified folder under wp and db.

That’s it, have fun.

WTF: /bin/rm: Argument list too long

Imagine you got a directory, with millions of files in it. If you ever had the error message “/bin/rm: Argument list too long”,
you’ll know what I mean.

Here’s a workaround with find.

For example you wanted to delete all pdf files in the directory, here is how to do with find:

find -mindepth 1 -maxdepth 1 -type f -name '*.pdf' -delete

Let’s split the command:

find --> sure, the name of the command
-mindepth 1 --> find will search at least 1 level in depth
-maxdepth 1 --> find will search maximum 1 level in depth
-type f --> search only for files(see man find for other types)
-name '*.pdf' --> search for files ending with .pdf(use -iname for case insensitive search --> damn slow)
-delete --> deletes all matching files

With find you have the full control, and no need to be afraid, that you accidentally delete more files.

Have Fun!

There are no more results.