    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>Linux.com :: easy script for backing up a directory then copying it acros</title>
        <link>http://www.linux.com/archive/forums/topic/2146</link>
        <description>Everything Linux and Open Source</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Linux.com Admin</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.linux.com" /> 
        <admin:errorReportsTo rdf:resource="mailto:noreply@linux.com" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>



<div class="xarbb-noteswrapper">
</div>

   <div class="xarbb-noteswrapper">
       <div class="xar-sub rightnote">
           <div>
                    <a href="http://www.linux.com/archive/forums/topic/2126">
Previous Topic</a>
|
                    <a href="http://www.linux.com/archive/forums/topic/2144">
Next Topic</a>
</div>

           <div>
                    <a href="http://www.linux.com/archive/forums/printtopic/2146?theme=print">
Print this topic</a> |
You are not subscribed            </div>
        </div>
        <div style="clear: both;"></div>
    </div>

    <h1>
        <a class="xar-title" href="http://www.linux.com/archive/forums/topic/2146">easy script for backing up a directory then copying it acros</a>
   </h1>


   <div class="xarbb-topiccontrols">
<form action="http://www.linux.com/archive/forums?func=jump" method="post">
   <label for="xarbb_jump_menu">Forum Jump</label>
    <select name="f" id="xarbb_jump_menu" onchange="this.form.submit();">
        <optgroup label="Options">
            <option value="5" selected="selected">
Please select forum            </option>
            <option value="5">--------------------</option>
        </optgroup>
        <optgroup label="Forums">
                <option value="1">New to Linux</option>
                <option value="2">Hardware</option>
                <option value="3">Linux Distributions</option>
                <option value="4">Applications</option>
                <option value="5">Programming and Development</option>
                <option value="6">Miscellaneous Discussion</option>
                <option value="7">Linux.com Writers Forum</option>
                <option value="8">Jobs</option>
        </optgroup>
    </select>
    <input type="submit" class="button" value="Jump" />
</form>
<div style="clear: both;"></div>
   </div>

   <div class="xarbb-topiccontrols">

<span class="xar-sub">
    <a href="http://www.linux.com/archive/forums">
Forum Index    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/category/4181">
        Forums 
    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/forum/5">
        Programming and Development   </a>
</span>
<div style="clear: both;"></div>
   </div>

<div class="xarbb-tablewrapper">



   <table>
       <tr>
           <th scope="col">
Author</th>
           <th scope="col">
Message</th>
       </tr>



            <tr>
                <td class="xar-norm author">
                    <div>
                        <a href="http://www.linux.com/archive/roles/405644">Severcool</a>
                   </div>
                   <div class="xar-sub">
Joined: Jun 30, 2008<br/>Posts: 3                        <br />
                        <a href="http://www.linux.com/archive/forums?by=405644&amp;func=searchtopics">
Other Topics</a>
                   </div>
               </td>

               <td class="xar-norm message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted Jun 30, 2008 at 8:47:53 PM</span>
                       </div>



<div style="float: left;">
                           <strong class="xar-sub">
Subject: easy script for backing up a directory then copying it acros                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div>
                        Hi all,

This is my first post in these forums. If I posted in the wrong place feel free to scold me.

I was wondering if someone would help me out with a very basic script. I need to create a backup of a directory on a Mac running OS X 10.5 using tar, then copy it across a Windows network to a Mac server running OS X 10.4.

The tar command I was trying to use goes like this:

tar -cfz [i]filename[/i].tar.gz /Users/[i]userdirectory[/i]

I'm not sure about the copying accross the network part. Also I was going to use cron to have it run every day at 3:30 am.

The Mac server is named AweMacSvr1 and the domain name is bob-andy.com as an example. 

Thanks!!
[i][/i][i][/i]<p class="hiddensignature">
Just a guy working for the man.</p>
</div>

                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/2146#top">
Back to top</a>
</td>
               <td class="xar-alt">

                        <a href="http://www.linux.com/archive/roles/405644">
                            <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                        </a>
                        <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=405644">
                            <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                       </a>
                            <a href="http://">
                                <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                           </a>
</td>
           </tr>





           <tr>
               <td class="xar-norm author">
                   <strong>

                            <a href="http://www.linux.com/archive/roles/401955">
                                Khabi                           </a>
</strong>

                   <span class="xar-sub">
<br />
Joined Apr 21, 2008<br/>Posts: 121<br />
                        <br />
                        <a href="http://www.linux.com/archive/forums?by=401955&amp;func=searchtopics">
Other Topics                        </a>
                    </span>
                </td>

                <td class="xar-accent message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted:
                                Jul 01, 2008 1:49:02 AM                           </span>
                       </div>
                       <div class="rightnote">
</div>
                       <div style="float:left;">
                           <strong class="xar-sub">
Subject:
                                <a name="1193541" href="http://www.linux.com/archive/forums/topic/2146#1193541">
                                    Re:  Re:  easy script for backing up a directory then copyin                                </a>
                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div style="clear: left;">
                        windows shares are normally called smb or samba shares in the *nix world.  What you want to do is create your tar, mount the share, copy it over, then unmount the share.

I don't have a mac to test any of this out, but the basic is something like this:

[code=xml]
#!/bin/bash
tar -cfz filename.tar.gz /Users/userdirectory
if [[ $? -eq 0 ]]
then
  mount_smbfs -W workgroup //user@SERVER/folder /mntpoint
  cp filename.tar.gz /mntpoint/
  umount /mntpoint
else
  echo &quot;Unable to tar the directory&quot;
fi
[/code]

Thats just the basics of it.  You probably want to make tar output the file to a specific directory, and probably even delete the file when you're done transfering it.
Also, I would suggest putting the filename as a variable at the start of the script, even the user and server name as well.  That way its easy to modify down the line if you need to.

If none of that makes sense, feel free to ask about it.  This should get you started though, and making you modify it should help you learn what you're doing.  :)

I also highly suggest reading:  http://tldp.org/LDP/abs/html/  to learn basic bash scripting.
[Modified by: Khabi on July 01, 2008 01:49 AM]
                    </div>
                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/2146#top">
Back to top</a>
</td>

               <td class="xar-alt">

                            <a href="http://www.linux.com/archive/roles/401955">
                                <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                            </a>
                            <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=401955">
                                <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                           </a>
                                <a href="http://">
                                    <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                               </a>
</td>
           </tr>

           <tr>
               <td class="xar-norm author">
                   <strong>

                            <a href="http://www.linux.com/archive/roles/405644">
                                Severcool                           </a>
</strong>

                   <span class="xar-sub">
<br />
Joined Jun 30, 2008<br/>Posts: 3<br />
                        <br />
                        <a href="http://www.linux.com/archive/forums?by=405644&amp;func=searchtopics">
Other Topics                        </a>
                    </span>
                </td>

                <td class="xar-norm message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted:
                                Jul 02, 2008 4:05:35 PM                           </span>
                       </div>
                       <div class="rightnote">
</div>
                       <div style="float:left;">
                           <strong class="xar-sub">
Subject:
                                <a name="1193653" href="http://www.linux.com/archive/forums/topic/2146#1193653">
                                    easy script for backing up a directory then copying it acros                                </a>
                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div style="clear: left;">
                        Thank you so much!! This will get me going in the right direction. I will let you know if I need anymore help. :)<p class="hiddensignature">
Just a guy working for the man.</p>
                    </div>
                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/2146#top">
Back to top</a>
</td>

               <td class="xar-alt">

                            <a href="http://www.linux.com/archive/roles/405644">
                                <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                            </a>
                            <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=405644">
                                <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                           </a>
                                <a href="http://">
                                    <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                               </a>
</td>
           </tr>

           <tr>
               <td class="xar-norm author">
                   <strong>

                            <a href="http://www.linux.com/archive/roles/405644">
                                Severcool                           </a>
</strong>

                   <span class="xar-sub">
<br />
Joined Jun 30, 2008<br/>Posts: 3<br />
                        <br />
                        <a href="http://www.linux.com/archive/forums?by=405644&amp;func=searchtopics">
Other Topics                        </a>
                    </span>
                </td>

                <td class="xar-accent message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted:
                                Jul 02, 2008 4:43:17 PM                           </span>
                       </div>
                       <div class="rightnote">
</div>
                       <div style="float:left;">
                           <strong class="xar-sub">
Subject:
                                <a name="1193655" href="http://www.linux.com/archive/forums/topic/2146#1193655">
                                    easy script for backing up a directory then copying it acros                                </a>
                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div style="clear: left;">
                        OK so I'm not copying to a Windows server it's a Mac server. herefore I don't think this command will work: mount_smbfs -W

<p class="hiddensignature">
Just a guy working for the man.</p>
                    </div>
                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/2146#top">
Back to top</a>
</td>

               <td class="xar-alt">

                            <a href="http://www.linux.com/archive/roles/405644">
                                <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                            </a>
                            <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=405644">
                                <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                           </a>
                                <a href="http://">
                                    <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                               </a>
</td>
           </tr>

           <tr>
               <td class="xar-norm author">
                   <strong>

                            <a href="http://www.linux.com/archive/roles/401955">
                                Khabi                           </a>
</strong>

                   <span class="xar-sub">
<br />
Joined Apr 21, 2008<br/>Posts: 121<br />
                        <br />
                        <a href="http://www.linux.com/archive/forums?by=401955&amp;func=searchtopics">
Other Topics                        </a>
                    </span>
                </td>

                <td class="xar-norm message">
                   <div class="xarbb-messagecontrols">
                       <div class="leftnote">
                           <span class="xar-sub">
Posted:
                                Jul 02, 2008 6:55:16 PM                           </span>
                       </div>
                       <div class="rightnote">
</div>
                       <div style="float:left;">
                           <strong class="xar-sub">
Subject:
                                <a name="1193662" href="http://www.linux.com/archive/forums/topic/2146#1193662">
                                    easy script for backing up a directory then copying it acros                                </a>
                            </strong>
                        </div>
                        <div style="clear: both;"></div>
                    </div>

                    <div style="clear: left;">
                        Ah, okay.  You had said a &quot;Windows network&quot; so I just assumed you were doing windows filesharing with that Mac.

So the only problem is I don't have a mac of my own to test any of this, but generically (I think the mac has these apps) these should be good alternatvies.  The syntax might change a little bit though.

Rsync:  rsync filename.tar.gz user@host:/destination/directory
scp:  scp filename.tar.gz user@host:/destination/directory

Both of these would require you to have a user on the remote machine, and ssh running on it as well.   For simple 1 file transfers I would recommend going with the scp method.  Rsync is more suited for keeping a directory on a remote machine in sync with one on a different machine.

There might be a better Mac specific way of doing this, but I'm not sure.  :)                    </div>
                </td>
            </tr>

            <tr>
                <td class="xar-norm author">
                    <a href="http://www.linux.com/archive/forums/topic/2146#top">
Back to top</a>
</td>

               <td class="xar-alt">

                            <a href="http://www.linux.com/archive/roles/401955">
                                <img src="modules/xarbb/xarimages/new/icon_profile.gif" alt="Profile" />
                            </a>
                            <a href="http://www.linux.com/archive/?module=roles&amp;func=email&amp;uid=401955">
                                <img src="modules/xarbb/xarimages/new/icon_email.gif" alt="Email" />
                           </a>
                                <a href="http://">
                                    <img src="modules/xarbb/xarimages/new/icon_www.gif" alt="Website" />
                               </a>
</td>
           </tr>
</table>
</div>

<div class="xarbb-topiccontrols">

<span class="xar-sub">
    <a href="http://www.linux.com/archive/forums">
Forum Index    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/category/4181">
        Forums 
    </a>
    <span style="font-size: larger;">&#187;</span>
    <a href="http://www.linux.com/archive/forums/forum/5">
        Programming and Development   </a>
</span>

</div>



            </channel>
</rss>
