Shell Script how to remove absolute paths from zip archive
Hi,
I need to write an bash script which works like it can copy files from remote machine through ssh to the server where script is running in zip format with the structure i want. I don't want to get absolute path in zip archive. Please let me know how it can be possible. ssh source-ip-address zip backup.zip /home/dir1/test.txt /home/dir1/test/test2.txt # /home/dir1/test2/txt is the source. unzip -l backup.zip > list.txt `cat list.txt` # list.txt contains /home/dir1/test.txt /home/dir1/test/test2.txt By default zip store absolute paths. While i don't want to store /home/dir1 & /home/dir2/ in zip archive. I need zip file in following format. test.txt test/test2.txt I know it is possible if i can change working directory when creating zip but as i am creating zip through remote machine, don't know how to change working directory. like it doesn't works ssh source-ip-address cd /home/dir1 ssh source-ip-address zip backup.zip test.txt test/test2.txt Or is there anyway that i can zip the files from root path means not to include common path in archive i.e. /home/dir1 Thanks, |
Why use zip. Use a native unix format such as tar.
Here is how you can perform a backup, using tar and don't need to have the actual tar file produced: tar -C / -cf - /home /usr /srv /bin /sbin | ssh user@host tar -C <backup_dir> -xvf - This will create the subdirectories that you don't want but the -C <dir> option allows you to change the base directory to start from and restore to, which is similar to your question. You could use cpio instead of tar. Here is an example which copies the files to my home directory in my desktop, via ssh. While the work/list* files are listed, without the -d option, they are all created in the same directory. ls index.html* work/list* | cpio --create -v | ssh hpmedia cpio -vi - If you do start from a tar or cpio file, you can simply cat the archive file through the pipe. |
All times are GMT -5. The time now is 12:54 PM. |