# Percona Xtrabackup for MySQL

**URL:** <https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501>\
**Category:** Percona XtraBackup\
**Tags:** mysql, percona\
**Created:** [April 2, 2024, 9:45am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501 "2024-04-02T09:45:41Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 2, 2024, 9:45am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/1 "2024-04-02T09:45:42Z")

</div>

I want to take backup from a remote server and need to restore the backup data to another server from my local machine, and I want to perform it with a single command, as take backup from the server-A and immediately restore it to server-B without storing it in a dump file. And I need to perform this using the xtrabackup tool for mysql.

Kindly anyone help me in this task

Thanks  
Gousik Rao N

---

<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:** [April 2, 2024, 12:54pm UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/2 "2024-04-02T12:54:24Z")

</div>

Hello @Wwe_Star,

> [@Wwe\_Star](#):
>
> And I need to perform this using the xtrabackup tool for mysql.

You cannot do this with Xtrabackup. Xtrabackup is a physical backup tool which requires local disk access. You cannot use Xtrabackup to take remote backups.

If you do not have local disk access, you will need to take a _logical_ backup using [mydumper](https://github.com/mydumper/mydumper).

---

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 2, 2024, 7:12pm UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/3 "2024-04-02T19:12:23Z")

</div>

So whether it is not possible by using XtraDB right ?

---

<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:** [April 2, 2024, 9:02pm UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/4 "2024-04-02T21:02:50Z")

</div>

XtraDB is a storage engine created by Percona which is an enhanced InnoDB.

Percona Xtrabackup (PXB) is a _physical_ backup tool, meaning it copies files on the disk from location A to location B. You need disk-level access on both servers to use PXB.

If you do not have disk access, you must take a _logical_ backup using mysqldump or mydumper.

---

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 3, 2024, 3:31am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/5 "2024-04-03T03:31:19Z")

</div>

Okay sir I understand that, If I can have disk level access then it is possible to take the backup and restore it in another server in a single command,

Note:I saw a post that it can by done using specific tools like that ?

---

<div class="post-metadata">

**Author:** ![smit.arora](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@smit.arora](https://forums.percona.com/u/smit.arora)\
**Post date:** [April 3, 2024, 2:43pm UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/6 "2024-04-03T14:43:07Z")

</div>

Hello @Wwe_Star  
If you have disk access, it is possible to restore to another server using two commands,  
one to take the backup, you can use streaming backup to avoid saving it on the server, and directly save on server B. These blog posts will help you in detailed steps-

> **[Streaming Percona XtraBackup for MySQL to Multiple Destinations](https://www.percona.com/blog/streaming-percona-xtrabackup-for-mysql-to-multiple-destinations/)**
>
> Ever had to provision a large number of instances from a single backup? Percona XtraBackup can help, performing backups of your MySQL data while the system is running.

> **[Streaming MySQL Backups with Percona XtraBackup - Another Alternative](https://www.percona.com/blog/streaming-mysql-backups-with-percona-xtrabackup-another-alternative/)**
>
> Presenting another way to make a MySQL database copy between servers using our Percona XtraBackup utility. 

But you will have to prepare the backup using the second command - [Prepare a full backup - Percona XtraBackup](https://docs.percona.com/percona-xtrabackup/8.0/prepare-full-backup.html)

If it has to be done in one command, you can use mysqldump and feed the output directly to MySQL which will have a higher chance of failure.

---

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 4, 2024, 3:35am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/7 "2024-04-04T03:35:08Z")

</div>

Okay let me try the solution you have gave !!

Any way thanks for your time !!!

---

<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:** [April 4, 2024, 4:38am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/8 "2024-04-04T04:38:12Z")

</div>

Yes, you can use a single command to take the backup and stream it to another server, but once the backup is on server 2, you must still prepare it, fix permissions, and then start MySQL.

---

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 4, 2024, 5:24am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/9 "2024-04-04T05:24:50Z")

</div>

Yeah that’s very very helpful sir can you please give me more info on this regard like how to perform this operation and can you provide with the command or resource for this

Thanks

---

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 4, 2024, 5:28am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/10 "2024-04-04T05:28:08Z")

</div>

ssh user@remote-server “xtrabackup --backup --user=username --password=password --stream=xbstream --parallel=4” | ssh username@remote-server “xtrabackup --parallel=4 --prepare --target-dir=/path/to/restored\_data”

Whether this command is correct to execute the above mentioned operation

---

<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:** [April 4, 2024, 12:18pm UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/11 "2024-04-04T12:18:09Z")

</div>

No, your command will not work. You cannot prepare the stream of data. You must fully copy the backup from remote to local, and then prepare it.

Here is how to backup and stream in 1 command. After this, you need to prepare the backup on the local, machine, then fix permissions, then start MySQL. You cannot do all of this in “1 command”.

```auto
    remote-server$ xtrabackup --backup --compress --stream=xbstream --target-dir=./ | ssh user@otherhost "xbstream -x"
    local-server$ xtrabackup --prepare --target-dir=./
    local-server$ chown -R mysql:mysql ./
    local-server$ systemctl start mysql

```

> **[Percona XtraBackup - Take a streaming backup](https://docs.percona.com/percona-xtrabackup/8.0/take-streaming-backup.html?h=ssh)**
>
> Percona XtraBackup supports streaming mode. Streaming mode sends a backup to STDOUT in the xbstream format instead of copying the files to the backup directory.

---

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 5, 2024, 3:23am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/12 "2024-04-05T03:23:53Z")

</div>

Thanks sir for your valuable reply, but I want to take backup from a remote server and I want to restore it to another remote server in a single command can you help me for this ?

---

<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:** [April 5, 2024, 3:44am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/13 "2024-04-05T03:44:05Z")

</div>

> [@Wwe\_Star](#):
>
> I want to take backup from a remote server and I want to restore it to another remote server in a single command

You cannot do this with a single command. It will require multiple commands as shown above. You can wrap all those commands into a single shell script and execute that one script as an alternative.

---

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 5, 2024, 4:49am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/14 "2024-04-05T04:49:06Z")

</div>

Ahh yes sir, whether its possible to take the backup from the remote server and then stream it directly to the another remote server in one command, and in the destination remote server we can prepare the backup separately to backup ?

---

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 6, 2024, 10:09am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/15 "2024-04-06T10:09:15Z")

</div>

Sir didn’t get the concept and my task is unfinished can you please help me with your valuable time

---

<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:** [April 6, 2024, 2:23pm UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/16 "2024-04-06T14:23:05Z")

</div>

Hello @Wwe_Star,  
The documentation and examples provided above should be enough to get a script written. Again, you cannot do all this in 1 command. You can use 1 command to stream the backup from A to B, but you will need local access to prepare the backup and then start mysql.

---

<div class="post-metadata">

**Author:** ![Wwe\_Star](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/wwe_star/32/15673_2.png) [@Wwe\_Star](https://forums.percona.com/u/Wwe_Star)\
**Post date:** [April 15, 2024, 10:24am UTC](https://forums.percona.com/t/percona-xtrabackup-for-mysql/29501/17 "2024-04-15T10:24:33Z")

</div>

ssh username@remote\_host1 “xtrabackup --backup -u root -p --stream=xbstream --compress --datadir=/path/to/data/dir” | ssh username@remote\_host2 “xbstream -x -C /path/to/backup”

whether this command is right to take a backup from the remote server A and then stream it to the another remote server B
