How can I redirect rsync output to a directory with date and time stamp?












-1















I want to redirect the output of rsync to a particular directory with the date and time stamp.



Example: rsync -r source-dir dest-dir/current-date-time



Is there any way the "current-date-time" folder can be created automatically?

My main aim is to run the rsync command in a cron job and I want the output to be stored in multiple directories (with the date and time) under destination.



Is that possible in single rsync command?



I do understand -t preserves modification time so I may use
rsync -avH -t <source> <dest> but is the directory creation (with date and time) possible at the destination?










share|improve this question





























    -1















    I want to redirect the output of rsync to a particular directory with the date and time stamp.



    Example: rsync -r source-dir dest-dir/current-date-time



    Is there any way the "current-date-time" folder can be created automatically?

    My main aim is to run the rsync command in a cron job and I want the output to be stored in multiple directories (with the date and time) under destination.



    Is that possible in single rsync command?



    I do understand -t preserves modification time so I may use
    rsync -avH -t <source> <dest> but is the directory creation (with date and time) possible at the destination?










    share|improve this question



























      -1












      -1








      -1








      I want to redirect the output of rsync to a particular directory with the date and time stamp.



      Example: rsync -r source-dir dest-dir/current-date-time



      Is there any way the "current-date-time" folder can be created automatically?

      My main aim is to run the rsync command in a cron job and I want the output to be stored in multiple directories (with the date and time) under destination.



      Is that possible in single rsync command?



      I do understand -t preserves modification time so I may use
      rsync -avH -t <source> <dest> but is the directory creation (with date and time) possible at the destination?










      share|improve this question
















      I want to redirect the output of rsync to a particular directory with the date and time stamp.



      Example: rsync -r source-dir dest-dir/current-date-time



      Is there any way the "current-date-time" folder can be created automatically?

      My main aim is to run the rsync command in a cron job and I want the output to be stored in multiple directories (with the date and time) under destination.



      Is that possible in single rsync command?



      I do understand -t preserves modification time so I may use
      rsync -avH -t <source> <dest> but is the directory creation (with date and time) possible at the destination?







      rsync






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 10:43









      peterh

      4,499113361




      4,499113361










      asked Mar 7 at 11:47









      Nibedita NandaNibedita Nanda

      1




      1






















          2 Answers
          2






          active

          oldest

          votes


















          1














          As far as I see, there is no possibility to create the directory from within the rsync command.



          But what about writing a simple bash script like this:



          #!/bin/bash
          myDate="$(date +%F)"
          mkdir -p "dest-dir/$myDate"
          rsync -r source-dir dest-dir/"$myDate"
          exit 0





          share|improve this answer





















          • 1





            The exit 0 at the end would mask any errors that rsync may produce in case this script is used in a conditional statement or similar context.

            – Kusalananda
            Mar 7 at 14:43













          • Thanks @Kusalananda for the edit and the comment on exit 0.

            – freiheitsnetz
            Mar 7 at 14:49





















          1














          You can use the command:



          rsync -avH <source> <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          Command substitution ($(...)) is used to create the name for a new directory under <dest> as the current date + time.



          Note that the above command will create the <source> directory under <dest>/<current_date-time>/. If you want to just copy the content of <source>, use:



          rsync -avH <source>/ <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          (relevant is the / after <source>).



          As mentioned in another answer you have, with some date implementations (e.g. GNU date), the %F format specifier can be used for "date in ISO format", thus abbreviating '%Y-%m-%d'. Note that %F is not specified in POSIX for the date utility (but many date implementations are able to use this format string as they depend on strftime(), which will support it).






          share|improve this answer





















          • 1





            It is true that %F is not in POSIX for the date utility, it is however defined for the strftime() C function, on which most date implementations rely.

            – Kusalananda
            Mar 8 at 10:50











          • @Kusalananda Thanks! I think this is really useful, feel free to edit my answer (implementation details are usually beyond my knowledge).

            – fra-san
            Mar 8 at 10:57












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f504902%2fhow-can-i-redirect-rsync-output-to-a-directory-with-date-and-time-stamp%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          As far as I see, there is no possibility to create the directory from within the rsync command.



          But what about writing a simple bash script like this:



          #!/bin/bash
          myDate="$(date +%F)"
          mkdir -p "dest-dir/$myDate"
          rsync -r source-dir dest-dir/"$myDate"
          exit 0





          share|improve this answer





















          • 1





            The exit 0 at the end would mask any errors that rsync may produce in case this script is used in a conditional statement or similar context.

            – Kusalananda
            Mar 7 at 14:43













          • Thanks @Kusalananda for the edit and the comment on exit 0.

            – freiheitsnetz
            Mar 7 at 14:49


















          1














          As far as I see, there is no possibility to create the directory from within the rsync command.



          But what about writing a simple bash script like this:



          #!/bin/bash
          myDate="$(date +%F)"
          mkdir -p "dest-dir/$myDate"
          rsync -r source-dir dest-dir/"$myDate"
          exit 0





          share|improve this answer





















          • 1





            The exit 0 at the end would mask any errors that rsync may produce in case this script is used in a conditional statement or similar context.

            – Kusalananda
            Mar 7 at 14:43













          • Thanks @Kusalananda for the edit and the comment on exit 0.

            – freiheitsnetz
            Mar 7 at 14:49
















          1












          1








          1







          As far as I see, there is no possibility to create the directory from within the rsync command.



          But what about writing a simple bash script like this:



          #!/bin/bash
          myDate="$(date +%F)"
          mkdir -p "dest-dir/$myDate"
          rsync -r source-dir dest-dir/"$myDate"
          exit 0





          share|improve this answer















          As far as I see, there is no possibility to create the directory from within the rsync command.



          But what about writing a simple bash script like this:



          #!/bin/bash
          myDate="$(date +%F)"
          mkdir -p "dest-dir/$myDate"
          rsync -r source-dir dest-dir/"$myDate"
          exit 0






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 at 14:42









          Kusalananda

          139k17259429




          139k17259429










          answered Mar 7 at 14:40









          freiheitsnetzfreiheitsnetz

          112




          112








          • 1





            The exit 0 at the end would mask any errors that rsync may produce in case this script is used in a conditional statement or similar context.

            – Kusalananda
            Mar 7 at 14:43













          • Thanks @Kusalananda for the edit and the comment on exit 0.

            – freiheitsnetz
            Mar 7 at 14:49
















          • 1





            The exit 0 at the end would mask any errors that rsync may produce in case this script is used in a conditional statement or similar context.

            – Kusalananda
            Mar 7 at 14:43













          • Thanks @Kusalananda for the edit and the comment on exit 0.

            – freiheitsnetz
            Mar 7 at 14:49










          1




          1





          The exit 0 at the end would mask any errors that rsync may produce in case this script is used in a conditional statement or similar context.

          – Kusalananda
          Mar 7 at 14:43







          The exit 0 at the end would mask any errors that rsync may produce in case this script is used in a conditional statement or similar context.

          – Kusalananda
          Mar 7 at 14:43















          Thanks @Kusalananda for the edit and the comment on exit 0.

          – freiheitsnetz
          Mar 7 at 14:49







          Thanks @Kusalananda for the edit and the comment on exit 0.

          – freiheitsnetz
          Mar 7 at 14:49















          1














          You can use the command:



          rsync -avH <source> <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          Command substitution ($(...)) is used to create the name for a new directory under <dest> as the current date + time.



          Note that the above command will create the <source> directory under <dest>/<current_date-time>/. If you want to just copy the content of <source>, use:



          rsync -avH <source>/ <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          (relevant is the / after <source>).



          As mentioned in another answer you have, with some date implementations (e.g. GNU date), the %F format specifier can be used for "date in ISO format", thus abbreviating '%Y-%m-%d'. Note that %F is not specified in POSIX for the date utility (but many date implementations are able to use this format string as they depend on strftime(), which will support it).






          share|improve this answer





















          • 1





            It is true that %F is not in POSIX for the date utility, it is however defined for the strftime() C function, on which most date implementations rely.

            – Kusalananda
            Mar 8 at 10:50











          • @Kusalananda Thanks! I think this is really useful, feel free to edit my answer (implementation details are usually beyond my knowledge).

            – fra-san
            Mar 8 at 10:57
















          1














          You can use the command:



          rsync -avH <source> <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          Command substitution ($(...)) is used to create the name for a new directory under <dest> as the current date + time.



          Note that the above command will create the <source> directory under <dest>/<current_date-time>/. If you want to just copy the content of <source>, use:



          rsync -avH <source>/ <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          (relevant is the / after <source>).



          As mentioned in another answer you have, with some date implementations (e.g. GNU date), the %F format specifier can be used for "date in ISO format", thus abbreviating '%Y-%m-%d'. Note that %F is not specified in POSIX for the date utility (but many date implementations are able to use this format string as they depend on strftime(), which will support it).






          share|improve this answer





















          • 1





            It is true that %F is not in POSIX for the date utility, it is however defined for the strftime() C function, on which most date implementations rely.

            – Kusalananda
            Mar 8 at 10:50











          • @Kusalananda Thanks! I think this is really useful, feel free to edit my answer (implementation details are usually beyond my knowledge).

            – fra-san
            Mar 8 at 10:57














          1












          1








          1







          You can use the command:



          rsync -avH <source> <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          Command substitution ($(...)) is used to create the name for a new directory under <dest> as the current date + time.



          Note that the above command will create the <source> directory under <dest>/<current_date-time>/. If you want to just copy the content of <source>, use:



          rsync -avH <source>/ <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          (relevant is the / after <source>).



          As mentioned in another answer you have, with some date implementations (e.g. GNU date), the %F format specifier can be used for "date in ISO format", thus abbreviating '%Y-%m-%d'. Note that %F is not specified in POSIX for the date utility (but many date implementations are able to use this format string as they depend on strftime(), which will support it).






          share|improve this answer















          You can use the command:



          rsync -avH <source> <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          Command substitution ($(...)) is used to create the name for a new directory under <dest> as the current date + time.



          Note that the above command will create the <source> directory under <dest>/<current_date-time>/. If you want to just copy the content of <source>, use:



          rsync -avH <source>/ <dest>/"$(date +'%Y-%m-%d-%H-%M-%S')"/


          (relevant is the / after <source>).



          As mentioned in another answer you have, with some date implementations (e.g. GNU date), the %F format specifier can be used for "date in ISO format", thus abbreviating '%Y-%m-%d'. Note that %F is not specified in POSIX for the date utility (but many date implementations are able to use this format string as they depend on strftime(), which will support it).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 8 at 10:59









          Kusalananda

          139k17259429




          139k17259429










          answered Mar 8 at 10:32









          fra-sanfra-san

          1,8991620




          1,8991620








          • 1





            It is true that %F is not in POSIX for the date utility, it is however defined for the strftime() C function, on which most date implementations rely.

            – Kusalananda
            Mar 8 at 10:50











          • @Kusalananda Thanks! I think this is really useful, feel free to edit my answer (implementation details are usually beyond my knowledge).

            – fra-san
            Mar 8 at 10:57














          • 1





            It is true that %F is not in POSIX for the date utility, it is however defined for the strftime() C function, on which most date implementations rely.

            – Kusalananda
            Mar 8 at 10:50











          • @Kusalananda Thanks! I think this is really useful, feel free to edit my answer (implementation details are usually beyond my knowledge).

            – fra-san
            Mar 8 at 10:57








          1




          1





          It is true that %F is not in POSIX for the date utility, it is however defined for the strftime() C function, on which most date implementations rely.

          – Kusalananda
          Mar 8 at 10:50





          It is true that %F is not in POSIX for the date utility, it is however defined for the strftime() C function, on which most date implementations rely.

          – Kusalananda
          Mar 8 at 10:50













          @Kusalananda Thanks! I think this is really useful, feel free to edit my answer (implementation details are usually beyond my knowledge).

          – fra-san
          Mar 8 at 10:57





          @Kusalananda Thanks! I think this is really useful, feel free to edit my answer (implementation details are usually beyond my knowledge).

          – fra-san
          Mar 8 at 10:57


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f504902%2fhow-can-i-redirect-rsync-output-to-a-directory-with-date-and-time-stamp%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to make a Squid Proxy server?

          Is this a new Fibonacci Identity?

          19世紀