# How to use xbstream to restore?

**URL:** <https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233>\
**Category:** Percona XtraBackup\
**Created:** [October 8, 2024, 1:41pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233 "2024-10-08T13:41:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdul\_Hannan\_Sohail](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/abdul_hannan_sohail/32/18426_2.png) [@Abdul\_Hannan\_Sohail](https://forums.percona.com/u/Abdul_Hannan_Sohail)\
**Post date:** [October 8, 2024, 1:41pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/1 "2024-10-08T13:41:14Z")

</div>

I am trying to backup using xtrabackup and i used the --stream=xbstream method. These backup files are directly then uploaded to the GCP bucket  
So i end up with xbstream file on the bucket.

I downloaded that file to the target server.  
What do i do now to restore the whole database using the xbstream file?

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [October 8, 2024, 3:27pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/2 "2024-10-08T15:27:25Z")

</div>

Hey @Abdul_Hannan_Sohail,  
I’m assuming you are using gsutil to copy the backup to GCP. For restore, cp the backup from GC to the machine. Run it through xbstream like this:

```
mkdir -p /path/to/restore
xbstream -xv -C /path/to/restore < backup.xbs

```

Then prepare it with PXB as normal.

I recommend you take a look at [xbcloud](https://docs.percona.com/percona-xtrabackup/8.0/xbcloud-binary-overview.html) which fully supports Google buckets using S3 mode. I just implemented this for a client last week.

High level: `xtrabackup --stream=xbstream | xbcloud put --storage=google ...` This way you don’t need any local disk access. The backup is streamed directly into GCP. Check the documentation for examples on how to restore.

---

<div class="post-metadata">

**Author:** ![Abdul\_Hannan\_Sohail](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/abdul_hannan_sohail/32/18426_2.png) [@Abdul\_Hannan\_Sohail](https://forums.percona.com/u/Abdul_Hannan_Sohail)\
**Post date:** [October 8, 2024, 4:34pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/3 "2024-10-08T16:34:30Z")

</div>

Hi Matthew  
Can you share what you mean by PXB as normal?

The command line I used to take backup is:  
xtrabackup --datadir=/var/lib/mysql --port=3306 --host=localhost --stream=xbstream --backup --target-dir=./ | /snap/bin/gsutil cp - “gs://bucket/DB.xbstream”

This creates a file called DB.xbstream on the GCP bucket.  
I am able to download this to the other target server where I want to restore.

I am not able to see online anywhere step by step on what to do now?  
some say to use xtrabackup -x and some say to use apply log something like that and its confusing.

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [October 8, 2024, 4:52pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/4 "2024-10-08T16:52:01Z")

</div>

```auto
# Copy the backup from gcloud to local fs
/snap/bin/gsutil cp “gs://bucket/DB.xbstream” /path/local/DB.xbstream

# Extract
xbstream -xv -C /path/to/restore < /path/local/DB.xbstream

# Pepare
xtrabackup prepare --target-dir /path/to/restore

# Fix permissions
chown -R mysql:mysql /path/to/restore

# Start mysql
systemctl start mysql

```

Our documentation has many HOWTO examples on the above.

---

<div class="post-metadata">

**Author:** ![Abdul\_Hannan\_Sohail](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/abdul_hannan_sohail/32/18426_2.png) [@Abdul\_Hannan\_Sohail](https://forums.percona.com/u/Abdul_Hannan_Sohail)\
**Post date:** [October 8, 2024, 5:04pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/5 "2024-10-08T17:04:19Z")

</div>

Thank you for the details  
just a question  
we dont need to use --copy-back option ?

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [October 8, 2024, 5:25pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/6 "2024-10-08T17:25:58Z")

</div>

You would use copy-back if you restored to some other location that wasn’t the mysql datadir.

---

<div class="post-metadata">

**Author:** ![Abdul\_Hannan\_Sohail](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/abdul_hannan_sohail/32/18426_2.png) [@Abdul\_Hannan\_Sohail](https://forums.percona.com/u/Abdul_Hannan_Sohail)\
**Post date:** [October 8, 2024, 6:32pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/7 "2024-10-08T18:32:46Z")

</div>

> [@matthewb](#):
>
> ```auto
> xbstream -xv -C /path/to/restore < /path/local/DB.xbstream
> 
> ```

so for this portion, you are using xbstream to extract. would we need to install xbstream as well? or will installing xtrabackup latest 8 version will automatically have this?

> [@matthewb](#):
>
> ```auto
> xtrabackup prepare --target-dir /path/to/restore
> 
> ```

and this “/path/to/restore” is the mysql data directory? the contents of which we would have removed after turning mysql off on the target server?

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [October 8, 2024, 7:27pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/8 "2024-10-08T19:27:33Z")

</div>

If you used xbstream to create the backup in the first place, then it should already be on you system. yes, installing PXB includes xbstream.

> [@Abdul\_Hannan\_Sohail](#):
>
> and this “/path/to/restore” is the mysql data directory? the contents of which we would have removed after turning mysql off on the target server?

Correct

---

<div class="post-metadata">

**Author:** ![Abdul\_Hannan\_Sohail](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/abdul_hannan_sohail/32/18426_2.png) [@Abdul\_Hannan\_Sohail](https://forums.percona.com/u/Abdul_Hannan_Sohail)\
**Post date:** [October 8, 2024, 8:39pm UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/9 "2024-10-08T20:39:09Z")

</div>

Also if we want to setup MySQL chained GTID based replication with xtrabackup

then we would need to use the slave of existing master-slave and deploy mysql native replication on slave to target server after doing a restore from the replica

regarding this method, what variables should be turned on the replica that would have been turned off if we werent using it as a intermediate master.

---

<div class="post-metadata">

**Author:** ![Abdul\_Hannan\_Sohail](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/abdul_hannan_sohail/32/18426_2.png) [@Abdul\_Hannan\_Sohail](https://forums.percona.com/u/Abdul_Hannan_Sohail)\
**Post date:** [October 10, 2024, 12:46am UTC](https://forums.percona.com/t/how-to-use-xbstream-to-restore/34233/10 "2024-10-10T00:46:56Z")

</div>

I used the

> [@matthewb](#):
>
> ```auto
> xbstream -xv -C /path/to/restore < /path/local/DB.xbstream
> 
> ```

but its giving me an error

xb\_stream\_read\_chunk(): wrong chunk magic at offset 0x0.  
exit code: 1
