Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    backup script help, sending a tar file to a remote server

    Hi all,
    This is to be part of a cronjob script.

    echo "tar backup directory ".$b
    tar zpcf - /home/erind/socprojects_backups/$b | ssh erind at serveripaddress "cat > socProjects.$b.tar"
    When I ran my script I got some kind of warning about removing leading / from the directory. Is that bad? The directory I am making a tar file of is the complete filesystem and code I would need to restore a web database if the live version were to crash. Am I doing something wrong that would prevent an easy process of just untarring this file back on the live server if I needed to?

    Secondly, since the cronjob is ran as root, I need to change the ownership and permissions of the tar file to erind, how can I do this if I immediately have the tar file sent to the backup server. Previously my script was just creating a tar file to save on the same server so I had this following the creation of the tar:

    chown erin socProjects.$b.tar
    chmod u+rw socProjects.$b.tar

    Thanks for any help,


  2. #2
    The warning about removing leading / is not bad. It just means that you have to be sure to specify that path when you are untarring, if you wish it to get put back in the same place, e.g.:

    tar -C / -xf /path/to/backup.tar
    As to file ownership, my first thought would be, why not run the cronjob as the user? If the user Id does not match up on the remote system, that would not work, though. So why not just add those chown/chmod commands as ssh calls to your backup script? e.g.:
    ssh erind at serveripaddress "chown erin socProjects.$b.tar;chmod u+rw socProjects.$b.tar"
    EDIT: Come to think of it, even if the cron is run as root, the file that gets created on the remote server should be owned by whomever you ssh in as - is this not the case?
    Last edited by atreyu; 10-19-2011 at 03:11 PM. Reason: wait...

  3. #3
    thanks for your help atreyu, im still working out problems with the script but what you said about file ownership makes sense

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts