# Running the sync script renders our server unresponsive

**URL:** <https://discourse.roots.io/t/running-the-sync-script-renders-our-server-unresponsive/26145>\
**Category:** plugins\
**Created:** [October 18, 2023, 6:03pm UTC](https://discourse.roots.io/t/running-the-sync-script-renders-our-server-unresponsive/26145 "2023-10-18T18:03:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![evance](https://discourse.roots.io/user_avatar/discourse.roots.io/evance/32/8447_2.png) [@evance](https://discourse.roots.io/u/evance)\
**Post date:** [October 18, 2023, 6:03pm UTC](https://discourse.roots.io/t/running-the-sync-script-renders-our-server-unresponsive/26145/1 "2023-10-18T18:03:47Z")

</div>

Hi there,

I have set up the [Sync Script](https://roots.io/products/sync-script/) for our project and wanted to copy the production DB over to our staging.

It did run successfully before but this time around I noticed that the _production server gets completely unresponsive when synching_…

That’s probably also due to the fact that we’re handling a rather big DB but ideally that shouldn’t be an issue.

So I was wondering if anyone has encountered something similar before and how you tackled it?

I could re-work the whole script to not use the `STDOUT`-export mechanism which (if I understand correctly) imports the remote (= prodcution) database locally and then re-uploads to my other remote (= staging) database.

That though stresses the server so much that nothing else gets through, I cannot access the backend or perform any task like adding a product to the shopping cart whilst the sync is in progress.

We tested with different machines to rule out any isolated local aspects and could confirm that the server is not responsive regardless of whom is trying to access it…

What are the main reasons for using this “on the fly via local”-approach vs. exporting to a file, `rsync`-ing between remote servers and then importing over at the target server?

Thanks & regards  
_Henning_

P.S.: Pinging @ben as you created the script and maybe have some deeper insight here…?

---

<div class="post-metadata">

**Author:** ![ben](https://discourse.roots.io/user_avatar/discourse.roots.io/ben/32/11377_2.png) [@ben](https://discourse.roots.io/u/ben)\
**Post date:** [October 19, 2023, 2:12pm UTC](https://discourse.roots.io/t/running-the-sync-script-renders-our-server-unresponsive/26145/2 "2023-10-19T14:12:11Z")

</div>

Howdy! Is this an issue with how the script uses standard output, or is this an issue with running `wp db export` on that server?

Can you try passing some of the flags mentioned here? [Speed up wp db export using WP-CLI · GitHub](https://gist.github.com/lukecav/f333618818b2be33bb8ff96a0d90faac)

> [@evance](#):
>
> What are the main reasons for using this “on the fly via local”-approach vs. exporting to a file, `rsync`-ing between remote servers and then importing over at the target server?

It’s just a cleaner approach from a code perspective, but if it’s causing these issues then I would just switch to using a file

---

<div class="post-metadata">

**Author:** ![evance](https://discourse.roots.io/user_avatar/discourse.roots.io/evance/32/8447_2.png) [@evance](https://discourse.roots.io/u/evance)\
**Post date:** [October 27, 2023, 5:30pm UTC](https://discourse.roots.io/t/running-the-sync-script-renders-our-server-unresponsive/26145/3 "2023-10-27T17:30:26Z")

</div>

Thanks for getting back and offering your help!

I’ve checked the additional flags and that is very handy indeed – in our case though that didn’t do the trick unfortunately…

I tweaked and enhanced your script to export to a file instead and `rsync` the DB. Just for reference if anyone else might need the same…

* * *

New **FROMCURRENT** and **TOCURRENT** vars for placing the files as well as a **TIMESTAMP** for the exports:

```bash
TIMESTAMP=$(date +%s)
[[$FROMDIR =~ ^(.*):]] && FROMHOST=${BASH_REMATCH[1]}
[[$FROMDIR =~ ^.*:((/[^/]+/[^/]+/[^/]+/)).*$ ]] && FROMCURRENT="${BASH_REMATCH[1]}current"
[[$TODIR =~ ^(.*):]] && TOHOST=${BASH_REMATCH[1]}
[[$TODIR =~ ^.*:((/[^/]+/[^/]+/[^/]+/)).*$ ]] && TOCURRENT="${BASH_REMATCH[1]}current"

```

File export & `rsync` steps:

```bash
wp "@$FROM" db export --default-character-set=utf8mb4 --all-tablespaces --single-transaction --quick --lock-tables=false export-$TIMESTAMP.sql
RSYNCDB=$(ssh -o ForwardAgent=yes $FROMHOST "rsync -aze 'ssh -o StrictHostKeyChecking=no' --progress $FROMCURRENT/export-$TIMESTAMP.sql $TOHOST:$TOCURRENT")
if [[$RSYNCDB == *"error"*]]; then
  echo "❌ rsync DB from $FROMSITE to $TOSITE failed: $RSYNCDB"
  exit 1
else
  echo "✅ rsync DB from $FROMSITE to $TOSITE"
fi

```

Remove export files after sync completes:

```bash
# Delete remote DB export files
DELETEDBFROM=$(ssh $FROMHOST "rm $FROMCURRENT/export-$TIMESTAMP.sql")
DELETEDBTO=$(ssh $TOHOST "rm $TOCURRENT/export-$TIMESTAMP.sql")

```

---

<div class="post-metadata">

**Author:** ![system](https://discourse.roots.io/user_avatar/discourse.roots.io/system/32/10306_2.png) [@system](https://discourse.roots.io/u/system)\
**Post date:** [November 29, 2023, 6:04pm UTC](https://discourse.roots.io/t/running-the-sync-script-renders-our-server-unresponsive/26145/4 "2023-11-29T18:04:30Z")

</div>

Closed on November 29, 2023, 6:04pm UTC

This topic was automatically closed after 42 days. New replies are no longer allowed.
