Forum Linux.redhat tar + split + output

Posté par  . Licence CC By‑SA.
Étiquettes :
-2
13
juil.
2015

Hello,

I have this command:

$TAR -cvf - $SOURCEDIR $EXCLUDEDIR | split --bytes=1999m - $BACKUP_DEVICE 1>/usr/backup/backuped_files.lst

this part is working as expected:

$TAR -cvf - $SOURCEDIR $EXCLUDEDIR | split --bytes=1999m - $BACKUP_DEVICE

this part is not working:

1>/usr/backup/backuped_files.lst

My purpose is to catch the backuped files in backuped_files.lst (screen output without errors)
Can you help me?

Regards,

Renaud

  • # stderr

    Posté par  (site web personnel) . Évalué à 1.

    Hello,

    These are the 2 standard outputs:
    1 is stdout
    2 is stderr

    To redirect error output, you should use 2>/usr/backup/backuped_files.lst

    Additionally, in order to redirect both stdout and stderr to a file, you could use &>/usr/backup/backuped_files.lst

    • [^] # Re: stderr

      Posté par  . Évalué à 1.

      hello,thanks,

      sorry, i don't want errors..
      my mistake

      i'd like to log the backuped files so the "screen" output without errors

      • [^] # Re: stderr

        Posté par  . Évalué à 2.

        when i use man tar, I have

        --index-file=FILE
        send verbose output to FILE

        this should do the trick.

        Il ne faut pas décorner les boeufs avant d'avoir semé le vent

        • [^] # Re: stderr

          Posté par  . Évalué à 1.

          thanks but my tar version doesn't have this option :(

      • [^] # Re: stderr

        Posté par  . Évalué à 1. Dernière modification le 15 juillet 2015 à 12:12.

        sorry, i don't want errors..

        when you redirect tar output to stdout (-f -), list of files (-v) is sent to stderr

        $ tar cf - test >/dev/null
        $ tar cvf - test >/dev/null
        test/
        test/a
        test/b
        $ tar cvf - test >/dev/null 2>&1
        $ 
        

        So this should work :

        $TAR -cvf - $SOURCEDIR $EXCLUDEDIR 2>/usr/backup/backuped_files.lst | split --bytes=1999m - $BACKUP_DEVICE
        
  • # Are you allowed to write output file ?

    Posté par  . Évalué à 2.

    What is the result of "touch /usr/backup/backuped_files.lst" ?

  • # You can't

    Posté par  . Évalué à 2.

    $TAR -cvf - $SOURCEDIR $EXCLUDEDIR | split --bytes=1999m - $BACKUP_DEVICE 1>/usr/backup/backuped_files.lst

    You try to use STDOUT to send your data to the split command, and the '-v' option of tar use stdout to display the name of backuped files …

    • [^] # Re: You can't

      Posté par  . Évalué à 2. Dernière modification le 13 juillet 2015 à 17:35.

      Try something like :

      mkfifo /tmp/pipe1; $TAR -cvf /tmp/pipe1 $SOURCEDIR $EXCLUDEDIR 1>/usr/backup/backuped_files.lst
      & split --bytes=1999m /tmp/pipe1 $BACKUP_DEVICE

      (don't forget to remove /tmp/pipe1 in your script).

      • [^] # Re: You can't

        Posté par  . Évalué à 2. Dernière modification le 14 juillet 2015 à 22:14.

        hello, thanks,

        it said split, too many arguments.

        i found a workaround (not clean but working…):

        i inserted tags (tar start and tar end)in my log file and i used /bin/sed to extract the tar command from it.

        #extract tar logs from backup.log to backuped_files.lst
        sed -n '/^tar start/,/^tar end/p' backup.log > backuped_files.lst
        #remove tar logs from backup.log
        sed '/^tar start/,/^tar end/d' backup.log > backup.log

        Regards,

        Renaud

        • [^] # Re: You can't

          Posté par  . Évalué à 1.

          the last command didn't work.

          i used:
          /bin/sed -i".bak" '/tar start/,/tar end/d' /usr/backup/backup.log

          -i[SUFFIX], --in-place[=SUFFIX]
          edit files in place (makes backup if extension supplied)

          Regards,

          Renaud

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.