script to move files and zipi

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
specimen

script to move files and zipi

Post by specimen »

I am not sure whether or not this subject is posted in the right forum.

I need to copy the entire contents of a partition on a networked windows machine (ex: \\10.1.42.xx\d:) and p7zip it into "\home\jeff\dump" folder on my mint box. The compressed file should be maximum deflated, save full path info of the source files and folders and have a date stamp in the filename (ex: backupfile28032014.7z )

Is this easily done and if so, would anyone post a script exaple? Thanks!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: script to move files and zipi

Post by Pilosopong Tasyo »

specimen wrote:I am not sure whether or not this subject is posted in the right forum.
Move from Newbie Questions to Scripts & Bash. FIFY. ;)
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
specimen

Re: script to move files and zipi

Post by specimen »

Thanks very much for doing this. Much appreciated!
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: script to move files and zipi

Post by xenopeek »

That would just be one command I think. Have a look at the 7zr manpage:

Code: Select all

man 7zr
Image
specimen

Re: script to move files and zip

Post by specimen »

Thanks very much. The actual compression bussiness is handled in one line:
(ex: sudo 7zr -t7z a //10.1.42.76/dump/backupfile.7z //source/ddrive mx5).

What im having trouble with is developing a bash script that deploys on a shedule and stamps the date into the zip file name to make it unique. Id like the file name to be something like this: backupfile30032014.7z indicating the date the script was deployed.

I know how to do this in a windows batch. I just want to get away from ms and need a helping hand.

Thanks for your time in replying!
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: script to move files and zipi

Post by xenopeek »

Replace "backupfile.7z" in your command with the following (this is for bash):

Code: Select all

backupfile$(date +%d%m%Y).7z
Personally, I prefer using YYYYMMDD format over DDMMYYY, as that sorts better on name :wink: That would be:

Code: Select all

backupfile$(date +%Y%m%d).7z
Image
specimen

Re: script to move files and zipi

Post by specimen »

Outstanding. Thank you so much for the example. Now that I think of it, I like your date suggestion better.
Locked

Return to “Scripts & Bash”