I would recommend you to use rsync instead, it will allow you to do a live system to system real synchronization without the need of temporary files. It also provides the benefit of doing incremental updates when you need to update the clone.
I would exclude only: /proc/ /sys /dev /tmp /mnt
On the clone system you will need to make sure /etc/fstab and /boot/grub/grub.cfg are updated with the UUIDs of the clone systems partitions.
If you have a database like mysql you will need to be carefull and stop the DB before performing the copy.
You can do 1. with the following command:
tar cvf archive.tar --transform 's,^,baseFolder/,' a b
The archive will contain:
$ tar tvf archive.tar
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 baseFolder/a/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 baseFolder/a/foo
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 baseFolder/b/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 baseFolder/b/bar
For 2. you can run tar
with multiple --transform
options:
tar cvf archive.tar --transform 's,^a,changed_a,' --transform 's,^b,changed_b,' a b
The archive will contain:
$ tar tvf archive.tar
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 changed_a/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 changed_a/foo
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 changed_b/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 changed_b/bar
For 3. you can combine 1. and 2. as follows:
tar cvf archive.tar --transform 's,^a,changed_a,' --transform 's,^b,changed_b,' --transform 's,^,baseFolder/,' a b
The archive will contain:
$ tar tvf archive.tar
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 baseFolder/changed_a/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 baseFolder/changed_a/foo
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 baseFolder/changed_b/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 baseFolder/changed_b/bar
Best Answer
Nevermind, I was overlooking the obvious by simply doing this: