How can I redirect rsync output to a directory with date and time stamp?
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
add a comment |
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
add a comment |
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
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
rsync
edited Mar 8 at 10:43
peterh
4,499113361
4,499113361
asked Mar 7 at 11:47
Nibedita NandaNibedita Nanda
1
1
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
1
Theexit 0
at the end would mask any errors thatrsync
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 onexit 0
.
– freiheitsnetz
Mar 7 at 14:49
add a comment |
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).
1
It is true that%F
is not in POSIX for thedate
utility, it is however defined for thestrftime()
C function, on which mostdate
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
1
Theexit 0
at the end would mask any errors thatrsync
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 onexit 0
.
– freiheitsnetz
Mar 7 at 14:49
add a comment |
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
1
Theexit 0
at the end would mask any errors thatrsync
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 onexit 0
.
– freiheitsnetz
Mar 7 at 14:49
add a comment |
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
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
edited Mar 7 at 14:42
Kusalananda♦
139k17259429
139k17259429
answered Mar 7 at 14:40
freiheitsnetzfreiheitsnetz
112
112
1
Theexit 0
at the end would mask any errors thatrsync
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 onexit 0
.
– freiheitsnetz
Mar 7 at 14:49
add a comment |
1
Theexit 0
at the end would mask any errors thatrsync
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 onexit 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
add a comment |
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).
1
It is true that%F
is not in POSIX for thedate
utility, it is however defined for thestrftime()
C function, on which mostdate
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
add a comment |
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).
1
It is true that%F
is not in POSIX for thedate
utility, it is however defined for thestrftime()
C function, on which mostdate
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
add a comment |
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).
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).
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 thedate
utility, it is however defined for thestrftime()
C function, on which mostdate
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
add a comment |
1
It is true that%F
is not in POSIX for thedate
utility, it is however defined for thestrftime()
C function, on which mostdate
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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