Backup strategies


Hi all,

I am curious on how people are backing up their EE 4 installs. I have seen the project by @mram but haven’t tried it yet.

Any other options?



Here’s mine


sites=$(ls $ee)
year=`date +%Y`
month=`date +%m`
day=`date +%d`
date=`date +%Y-%m-%d`

mkdir -p $backup/$year/$month/$day

for i in $sites
	ee shell $i --command="wp db export $i.sql"
	cd $ee/$i/app && tar cfJ - htdocs | (pv -ptrb > $i.tar.xz)
	rm $ee/$i/app/htdocs/$i.sql
	mv $ee/$i/app/$i.tar.xz $backup/$year/$month/$day

chown -R cim:cim $backup


@timl thanks for the mention. I am still working away on the ee4-tools scripts when I have time. Contributions and suggestions are welcome.

@cim A couple of suggestions. You might not want to drop the .sql in a publicly accessible folder. Export it to ../$i.sql. Also, for small VMs (~1GB ram) and lots of files xz can consume more ram than available. After much testing I had to go back to gzip.


Noted, but my server has 32gb of ram so that’s not an issue for me. Like all code, it can be modified to fit your needs. Also the sql file is removed as you can see in line 17. My script works for my use case and I also wrote a restore script that goes along with this.


@cim Yep, fully understand your position. The fear with the .sql file in the htdocs folder is just in case something goes wrong. It’s just a defensive programming technique. As for ram, you have more than enough ram to xz -9e and get the smallest files on the planet! :slight_smile: Thanks for sharing and being a part of the community.


Thanks @cim and @mram for sharing and for the food for thought.

I will soon be experimenting with rsnapshot as well to reduce the amount of disk space used by the backups. It doesn’t create a nice archive file for easy download but it at least makes great use of symlinks.


I have tried this script with several time manually it works like charm. Thanks for that.
But the problem is when I am running this on crontab it gives me these errors.
/bin/sh: 1: ee: not found

But when I tried to add PATH vars I get
Error: EasyEngine requires docker-compose.

Is there anyway to fix this guys?


You have to log in as root or sudo -I and set your cron as root.


Oh wait, you have to use bash /script/path/name not sh or ./

ee not found? Either your install is glitched or not properly configured. The ee command requires root or sudo privileges.


I have already tried that one What I get for log is only this message
the input device is not a TTY
and obviously that sql file remove faiiled message…

I am running as root


Seems like this was an issue with v4 Import sql dB v4

sites=$(ls $ee)
year=`date +%Y`
month=`date +%m`
day=`date +%d`
date=`date +%Y-%m-%d`

mkdir -p $backup/$year/$month/$day

for i in $sites
        #ee shell $i --command="wp db export $i.sql"
        db_user=`ee site info $i | grep 'DB User' | awk -F '|' '{print $3}' | awk '{print $1}'`
		db_password=`ee site info $i | grep 'DB Password' | awk -F '|' '{print $3}' | awk '{print $1}'`
		db_host=`ee site info $i | grep 'DB Host' | awk -F '|' '{print $3}' | awk '{print $1}'`
		db_name=`ee site info $i | grep 'DB Name' | awk -F '|' '{print $3}' | awk '{print $1}'`
        docker exec ee-global-db bash -c "mysqldump --no-create-db --opt --add-drop-table -Q -h $db_host -u $db_user -p$db_password $db_name" > $ee/$i/app/htdocs/$i.sql
        cd $ee/$i/app && tar cfJ - htdocs | (pv -ptrb > $i.tar.xz)
        rm $ee/$i/app/htdocs/$i.sql
        mv $ee/$i/app/$i.tar.xz $backup/$year/$month/$day

chown -R root:root $backup

Works like a charm… Thanks @cim. Your a life save…
I am really looking forward to see the rsnapshot :smile: It would save a lot of space in the long run.


Thanks @cim for the script. I’ve changed the compression from xz to gz since it was painfully slow. xz was ~2mb/s vs gz ~16mb/s. I’ll accept the file size penalty.

I am also doing some tests with escaping the mysql password since I’ve had issues on one of my sites.


@cim I used your script for backing up the sites, do you mind sharing the script for restore as well ? thanks


I have long deleted and moved on from EEv4 but I rewrote the script from memory, use this script on a dummy site and also use at your own risk :wink:

# $1 = domain.tld
# $2 = 2000/01/01 (Y/m/d format)
# bash restore domain.tld 2019/02/22


cd $backup && tar -xzf $1.tar.gz
sudo rm -rf $ee/$1/app/htdocs
sudo mv $backup/htdocs $ee/$1/app
# when you export a db from wp cli, it'll drop the existing table if it exists
sudo ee shell $1 --command="wp db import $1.sql"
sudo rm $ee/$1/app/htdocs/$1.sql
chown -R www-data:www-data $ee/$1/app/htdocs


And where did you go?


Making my own docker stack using traefik, mariadb, and wordpress images. Traefik just makes life easier if I wanna connect other images, which I do, like Rocket.Chat, Gitea,, etc.


So you want to orchestrate your infastructure, in a docker than a server level, with custom open source diployments in far less price than big names do. It looks superb as a idea though, i wish it could implement ee.v4
In my mind it looks hard to build a full custom automation for back end. And front end, customer view?


It’s not hard as you think once you get the idea of how each component works. The head banging on the desk comes when you try to put them together lol.




I’ve also found it difficult to plan on to add additional services onto EEV4. For example, I really want to run rocketchat, nextcloud, bitwarden etc behind the nginx-proxy container that handles ssl. Can anybody explain the basics of where I’m going to start a new container that connects to the one Easyengine already uses?

Also, I run portainer on the machine now, but can’t get it to terminate https behind the nginx-proxy that already is installed. I find it helpful to give me a view of what’s going on under the hood.