ericbrandl
(ericb08132)
1
Hello all,
How do I tar everything in a dir (sub folders, files ) keeping permissions/dates, and no compression.
I have two servers each with a /appname/ dir at root of the drive. I want to take everything under /appname/ on one server tar it to a shared mount point on a nas and then unpack the contents from the nas to the other servers /appname/ keeping the structure permissions and dates intact.
What I have right now:
tar -vcf /nas/appfolder/servername-old/appnamebackup.tar.gz /appname/
But that looks like it tared the whole /appname/ dir and when it s unpacked it would unpack /appname/appname/ on the new server.
2 Spice ups
robhall
(robhall)
2
You’re backwards -
tar -zcv /appname/ -f /nas/appfolder/servername-old/appnamebackup.tar.gz
robhall
(robhall)
3
and FWIW, tar -cv only creates a .tar file.
tar -zcv creates a .tar.gz, and tar -jcv will create a .tar.bz2.
ericbrandl
(ericb08132)
4
That still backed up the entire /appname/ dir so when it was restored it was /appname/appname/ The /appname/ folder exists on both servers already and I just want to move the contents of the folder on one server to the other. I don’t want to tar the top level folder /appname/ I want to tar everything in it and then extract it into a folder on the other server.
If you’re not wanting to include the directory structure in the tar file you’re creating, take a look at the discussion and examples listed here: archive - How do I tar a directory of files and folders without including the directory itself? - Stack Overflow
Also, is this to be a one-time copy or something you do periodically to keep two locations in sync? You may want to look into a network-capable file copy program instead of tar if you’re wanting to keep the files/folders mirrored.
ericbrandl
(ericb08132)
7
This was for a one time move when swapping out old web servers with new ones. Pleas let me know if you seen any issues with this method. It seemed to work.
Got this from: Extract without First Directory
On the old server:
tar -cv /appname/ -f /nas/appnameappxfer/servername/appnameAppbackup.tar
On the new server:
tar -vxf /nas/appnameappxfer/servername/appnameAppbackup.tar -C /appname/ --strip 1
pigdog
(pigdog)
8
cd /appname && tar vcf /path/to/archive/appnamebackup.tar .
The trailing dot means the current directory. It will be pre-pended to all files in the archive.
eg:
$ cd /appname
$ tar vcf /tmp/archive.tar .
./
./file.1
./file.5
./file.2
./file.0
./file.7
./file.6
./file.3
./file.8
./file.4
./file.9
$ tar vtf /tmp/archive.tar
drwxr-xr-x root/root 0 2016-02-21 14:38 ./
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.1
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.5
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.2
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.0
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.7
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.6
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.3
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.8
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.4
-rw-r--r-- root/root 0 2016-02-21 14:38 ./file.9
If this is a process that has to be repeated, you might find it more efficient with rsync.
sb64711
(minimoog)
9
Just use Rsync to copy the files over to the new server instead of using tar.