Test if btrfs subvolume exists
I have a problem in a bash procedure, which should port my old rsync disk backup (and archive) to my future btrfs snapshot backup.
I want to use the line:
# btrfs subvolume snapshot /targetdir/@monthly.9 /targetdir/@monthly.8
If the snapshot /targetdir/@monthly.8 does not jet exist, then it gets created, as I want to.
But if /targetdir/@monthly.8 was there already, then /targetdir/@monthly.8/@onthly.9 gets created instead.
I am missing here a test for existence, say:
# [[ -bsnap <snap-path> ]] # =TRUE if <snap-path> exists and is a snap!
How can I overcome this problem?
bash backup btrfs ubuntu-18.04 snapshot
add a comment |
I have a problem in a bash procedure, which should port my old rsync disk backup (and archive) to my future btrfs snapshot backup.
I want to use the line:
# btrfs subvolume snapshot /targetdir/@monthly.9 /targetdir/@monthly.8
If the snapshot /targetdir/@monthly.8 does not jet exist, then it gets created, as I want to.
But if /targetdir/@monthly.8 was there already, then /targetdir/@monthly.8/@onthly.9 gets created instead.
I am missing here a test for existence, say:
# [[ -bsnap <snap-path> ]] # =TRUE if <snap-path> exists and is a snap!
How can I overcome this problem?
bash backup btrfs ubuntu-18.04 snapshot
My btrfs-progs v4.4 here on ubuntu 16.4 (dayly up to date) seems to overinterprete the man btrfs-subvolume, that says: "... snapshot [-r] <source> <dest>|[<dest>/]<name> ... If only <dest> is given, the subvolume will be named the basename of <source>." It seems to add imlicitly: "If <dest>/name exists already, then create <dest>/<name>/$(basename <source>)". I would call it a bug, or an evil feature.
– prometheos
Mar 8 '18 at 18:10
add a comment |
I have a problem in a bash procedure, which should port my old rsync disk backup (and archive) to my future btrfs snapshot backup.
I want to use the line:
# btrfs subvolume snapshot /targetdir/@monthly.9 /targetdir/@monthly.8
If the snapshot /targetdir/@monthly.8 does not jet exist, then it gets created, as I want to.
But if /targetdir/@monthly.8 was there already, then /targetdir/@monthly.8/@onthly.9 gets created instead.
I am missing here a test for existence, say:
# [[ -bsnap <snap-path> ]] # =TRUE if <snap-path> exists and is a snap!
How can I overcome this problem?
bash backup btrfs ubuntu-18.04 snapshot
I have a problem in a bash procedure, which should port my old rsync disk backup (and archive) to my future btrfs snapshot backup.
I want to use the line:
# btrfs subvolume snapshot /targetdir/@monthly.9 /targetdir/@monthly.8
If the snapshot /targetdir/@monthly.8 does not jet exist, then it gets created, as I want to.
But if /targetdir/@monthly.8 was there already, then /targetdir/@monthly.8/@onthly.9 gets created instead.
I am missing here a test for existence, say:
# [[ -bsnap <snap-path> ]] # =TRUE if <snap-path> exists and is a snap!
How can I overcome this problem?
bash backup btrfs ubuntu-18.04 snapshot
bash backup btrfs ubuntu-18.04 snapshot
edited Jan 14 at 0:14
prometheos
asked Mar 8 '18 at 17:54
prometheosprometheos
33
33
My btrfs-progs v4.4 here on ubuntu 16.4 (dayly up to date) seems to overinterprete the man btrfs-subvolume, that says: "... snapshot [-r] <source> <dest>|[<dest>/]<name> ... If only <dest> is given, the subvolume will be named the basename of <source>." It seems to add imlicitly: "If <dest>/name exists already, then create <dest>/<name>/$(basename <source>)". I would call it a bug, or an evil feature.
– prometheos
Mar 8 '18 at 18:10
add a comment |
My btrfs-progs v4.4 here on ubuntu 16.4 (dayly up to date) seems to overinterprete the man btrfs-subvolume, that says: "... snapshot [-r] <source> <dest>|[<dest>/]<name> ... If only <dest> is given, the subvolume will be named the basename of <source>." It seems to add imlicitly: "If <dest>/name exists already, then create <dest>/<name>/$(basename <source>)". I would call it a bug, or an evil feature.
– prometheos
Mar 8 '18 at 18:10
My btrfs-progs v4.4 here on ubuntu 16.4 (dayly up to date) seems to overinterprete the man btrfs-subvolume, that says: "... snapshot [-r] <source> <dest>|[<dest>/]<name> ... If only <dest> is given, the subvolume will be named the basename of <source>." It seems to add imlicitly: "If <dest>/name exists already, then create <dest>/<name>/$(basename <source>)". I would call it a bug, or an evil feature.
– prometheos
Mar 8 '18 at 18:10
My btrfs-progs v4.4 here on ubuntu 16.4 (dayly up to date) seems to overinterprete the man btrfs-subvolume, that says: "... snapshot [-r] <source> <dest>|[<dest>/]<name> ... If only <dest> is given, the subvolume will be named the basename of <source>." It seems to add imlicitly: "If <dest>/name exists already, then create <dest>/<name>/$(basename <source>)". I would call it a bug, or an evil feature.
– prometheos
Mar 8 '18 at 18:10
add a comment |
2 Answers
2
active
oldest
votes
I guess you don't want to run btrfs subvolume snapshot …
if /targetdir/@monthly.8
exists, regardless what it is. Just test if it exists:
[ -e /targetdir/@monthly.8 ]
or doesn't exist
[ ! -e /targetdir/@monthly.8 ]
whatever is more useful. If it exists when it shouldn't then btrfs subvolume delete
it. Only if this command returns ERROR: not a subvolume
do worry what else the object is. I advise you to organize your workflow, subvolumes, mountpoints, directories and their permissions in a way that @monthly.8
could only be a subvolume.
But if you really need to know
btrfs subvolume show /targetdir/@monthly.8
will succeed if it's a subvolume; it will fail otherwise. Example:
btrfs subvolume show /targetdir/@monthly.8 &>/dev/null && echo "It's a subvolume!"
I would like to add my command as a further option in your answer. Then I woud delete my answer, in order to stremline the argument a little. I don't think I am soo picky!
– prometheos
Mar 10 '18 at 23:41
@prometheos See Can I answer my own question? Our answers can coexist. You can accept your own answer if it suits you better.
– Kamil Maciorowski
Mar 11 '18 at 0:20
Sorry @Kamil Maciorowski that so much time has passed before me to accept the answer. Just now I urgently need this feature, and this answer is the most useful I can think of to wrap into a function, like - in bash:probe-subvolume() { btrfs subvolume show $1 &>/dev/null && { true; } || { false; }; }
– prometheos
Jan 14 at 0:05
@prometheos It's OK. Just curious: in what aspect isfoo && { true; } || { false; }
better than justfoo
?
– Kamil Maciorowski
Jan 14 at 5:02
" oh yes, I see! The cut-and-paste-devil hit me, somehow. I had first coded for textual ourput, like ` ...|| echo "$1 is either not a subvolume or not existant."; false; }. Here I used "false" for having the right return code: echo <text> would be allways "sucessful". Then I found that "weniger ist mehr" and removed the text, leaving the rest. You are right: even less ist even better. My shortened code (gets so short that one could do whithout the function!):
probe-subvolume() { btrfs subvolume show $1 &>/dev/null; } ` For @Kamil Maciorowski
– prometheos
Jan 15 at 0:51
add a comment |
The answer by @Kamil Maciorowski is good. But let me concentrate onto the existence test.
Say I am debugging, and I need to repeat a try, and the target snapshot was already there. Then I was very cautious and sat "bash -e" (i.e. the first error exits my shell. Remember that I must run it as root...). Then I prefer a command that tells me what happened, and then exits. Therefore I do:
btrfs subvolume list /targetdir/@monthly.9 | grep @monthly.8 && echo "$0 ERROR: snapshot /targetdir/@monthly.8 exists already!" && exit
Command "subvolume list " gives no error and lists them all. Then I filter as I need and make my decisions.
Oops! Why did my answer jump to the top? I tought they go chronologically, if they have no votes.
– prometheos
Mar 10 '18 at 23:44
Chronologically if you click "oldest" just above the first answer. This is per user preference and the site is not a forum.
– Kamil Maciorowski
Mar 11 '18 at 0:14
I hope you are aware it does not test exactly for/targetdir/@monthly.8
. I think any subvolume with@monthly.8
in its path (I mean internal path in the filesystem) will triggerecho
, even if this particular subvolume is not reachable in your directory tree at the moment. My solution, on the other hand, tests exactly the object appearing as/targetdir/@monthly.8
in the directory tree.
– Kamil Maciorowski
Mar 11 '18 at 0:38
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fsuperuser.com%2fquestions%2f1301671%2ftest-if-btrfs-subvolume-exists%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
I guess you don't want to run btrfs subvolume snapshot …
if /targetdir/@monthly.8
exists, regardless what it is. Just test if it exists:
[ -e /targetdir/@monthly.8 ]
or doesn't exist
[ ! -e /targetdir/@monthly.8 ]
whatever is more useful. If it exists when it shouldn't then btrfs subvolume delete
it. Only if this command returns ERROR: not a subvolume
do worry what else the object is. I advise you to organize your workflow, subvolumes, mountpoints, directories and their permissions in a way that @monthly.8
could only be a subvolume.
But if you really need to know
btrfs subvolume show /targetdir/@monthly.8
will succeed if it's a subvolume; it will fail otherwise. Example:
btrfs subvolume show /targetdir/@monthly.8 &>/dev/null && echo "It's a subvolume!"
I would like to add my command as a further option in your answer. Then I woud delete my answer, in order to stremline the argument a little. I don't think I am soo picky!
– prometheos
Mar 10 '18 at 23:41
@prometheos See Can I answer my own question? Our answers can coexist. You can accept your own answer if it suits you better.
– Kamil Maciorowski
Mar 11 '18 at 0:20
Sorry @Kamil Maciorowski that so much time has passed before me to accept the answer. Just now I urgently need this feature, and this answer is the most useful I can think of to wrap into a function, like - in bash:probe-subvolume() { btrfs subvolume show $1 &>/dev/null && { true; } || { false; }; }
– prometheos
Jan 14 at 0:05
@prometheos It's OK. Just curious: in what aspect isfoo && { true; } || { false; }
better than justfoo
?
– Kamil Maciorowski
Jan 14 at 5:02
" oh yes, I see! The cut-and-paste-devil hit me, somehow. I had first coded for textual ourput, like ` ...|| echo "$1 is either not a subvolume or not existant."; false; }. Here I used "false" for having the right return code: echo <text> would be allways "sucessful". Then I found that "weniger ist mehr" and removed the text, leaving the rest. You are right: even less ist even better. My shortened code (gets so short that one could do whithout the function!):
probe-subvolume() { btrfs subvolume show $1 &>/dev/null; } ` For @Kamil Maciorowski
– prometheos
Jan 15 at 0:51
add a comment |
I guess you don't want to run btrfs subvolume snapshot …
if /targetdir/@monthly.8
exists, regardless what it is. Just test if it exists:
[ -e /targetdir/@monthly.8 ]
or doesn't exist
[ ! -e /targetdir/@monthly.8 ]
whatever is more useful. If it exists when it shouldn't then btrfs subvolume delete
it. Only if this command returns ERROR: not a subvolume
do worry what else the object is. I advise you to organize your workflow, subvolumes, mountpoints, directories and their permissions in a way that @monthly.8
could only be a subvolume.
But if you really need to know
btrfs subvolume show /targetdir/@monthly.8
will succeed if it's a subvolume; it will fail otherwise. Example:
btrfs subvolume show /targetdir/@monthly.8 &>/dev/null && echo "It's a subvolume!"
I would like to add my command as a further option in your answer. Then I woud delete my answer, in order to stremline the argument a little. I don't think I am soo picky!
– prometheos
Mar 10 '18 at 23:41
@prometheos See Can I answer my own question? Our answers can coexist. You can accept your own answer if it suits you better.
– Kamil Maciorowski
Mar 11 '18 at 0:20
Sorry @Kamil Maciorowski that so much time has passed before me to accept the answer. Just now I urgently need this feature, and this answer is the most useful I can think of to wrap into a function, like - in bash:probe-subvolume() { btrfs subvolume show $1 &>/dev/null && { true; } || { false; }; }
– prometheos
Jan 14 at 0:05
@prometheos It's OK. Just curious: in what aspect isfoo && { true; } || { false; }
better than justfoo
?
– Kamil Maciorowski
Jan 14 at 5:02
" oh yes, I see! The cut-and-paste-devil hit me, somehow. I had first coded for textual ourput, like ` ...|| echo "$1 is either not a subvolume or not existant."; false; }. Here I used "false" for having the right return code: echo <text> would be allways "sucessful". Then I found that "weniger ist mehr" and removed the text, leaving the rest. You are right: even less ist even better. My shortened code (gets so short that one could do whithout the function!):
probe-subvolume() { btrfs subvolume show $1 &>/dev/null; } ` For @Kamil Maciorowski
– prometheos
Jan 15 at 0:51
add a comment |
I guess you don't want to run btrfs subvolume snapshot …
if /targetdir/@monthly.8
exists, regardless what it is. Just test if it exists:
[ -e /targetdir/@monthly.8 ]
or doesn't exist
[ ! -e /targetdir/@monthly.8 ]
whatever is more useful. If it exists when it shouldn't then btrfs subvolume delete
it. Only if this command returns ERROR: not a subvolume
do worry what else the object is. I advise you to organize your workflow, subvolumes, mountpoints, directories and their permissions in a way that @monthly.8
could only be a subvolume.
But if you really need to know
btrfs subvolume show /targetdir/@monthly.8
will succeed if it's a subvolume; it will fail otherwise. Example:
btrfs subvolume show /targetdir/@monthly.8 &>/dev/null && echo "It's a subvolume!"
I guess you don't want to run btrfs subvolume snapshot …
if /targetdir/@monthly.8
exists, regardless what it is. Just test if it exists:
[ -e /targetdir/@monthly.8 ]
or doesn't exist
[ ! -e /targetdir/@monthly.8 ]
whatever is more useful. If it exists when it shouldn't then btrfs subvolume delete
it. Only if this command returns ERROR: not a subvolume
do worry what else the object is. I advise you to organize your workflow, subvolumes, mountpoints, directories and their permissions in a way that @monthly.8
could only be a subvolume.
But if you really need to know
btrfs subvolume show /targetdir/@monthly.8
will succeed if it's a subvolume; it will fail otherwise. Example:
btrfs subvolume show /targetdir/@monthly.8 &>/dev/null && echo "It's a subvolume!"
edited Mar 8 '18 at 18:56
answered Mar 8 '18 at 18:50
Kamil MaciorowskiKamil Maciorowski
26k155680
26k155680
I would like to add my command as a further option in your answer. Then I woud delete my answer, in order to stremline the argument a little. I don't think I am soo picky!
– prometheos
Mar 10 '18 at 23:41
@prometheos See Can I answer my own question? Our answers can coexist. You can accept your own answer if it suits you better.
– Kamil Maciorowski
Mar 11 '18 at 0:20
Sorry @Kamil Maciorowski that so much time has passed before me to accept the answer. Just now I urgently need this feature, and this answer is the most useful I can think of to wrap into a function, like - in bash:probe-subvolume() { btrfs subvolume show $1 &>/dev/null && { true; } || { false; }; }
– prometheos
Jan 14 at 0:05
@prometheos It's OK. Just curious: in what aspect isfoo && { true; } || { false; }
better than justfoo
?
– Kamil Maciorowski
Jan 14 at 5:02
" oh yes, I see! The cut-and-paste-devil hit me, somehow. I had first coded for textual ourput, like ` ...|| echo "$1 is either not a subvolume or not existant."; false; }. Here I used "false" for having the right return code: echo <text> would be allways "sucessful". Then I found that "weniger ist mehr" and removed the text, leaving the rest. You are right: even less ist even better. My shortened code (gets so short that one could do whithout the function!):
probe-subvolume() { btrfs subvolume show $1 &>/dev/null; } ` For @Kamil Maciorowski
– prometheos
Jan 15 at 0:51
add a comment |
I would like to add my command as a further option in your answer. Then I woud delete my answer, in order to stremline the argument a little. I don't think I am soo picky!
– prometheos
Mar 10 '18 at 23:41
@prometheos See Can I answer my own question? Our answers can coexist. You can accept your own answer if it suits you better.
– Kamil Maciorowski
Mar 11 '18 at 0:20
Sorry @Kamil Maciorowski that so much time has passed before me to accept the answer. Just now I urgently need this feature, and this answer is the most useful I can think of to wrap into a function, like - in bash:probe-subvolume() { btrfs subvolume show $1 &>/dev/null && { true; } || { false; }; }
– prometheos
Jan 14 at 0:05
@prometheos It's OK. Just curious: in what aspect isfoo && { true; } || { false; }
better than justfoo
?
– Kamil Maciorowski
Jan 14 at 5:02
" oh yes, I see! The cut-and-paste-devil hit me, somehow. I had first coded for textual ourput, like ` ...|| echo "$1 is either not a subvolume or not existant."; false; }. Here I used "false" for having the right return code: echo <text> would be allways "sucessful". Then I found that "weniger ist mehr" and removed the text, leaving the rest. You are right: even less ist even better. My shortened code (gets so short that one could do whithout the function!):
probe-subvolume() { btrfs subvolume show $1 &>/dev/null; } ` For @Kamil Maciorowski
– prometheos
Jan 15 at 0:51
I would like to add my command as a further option in your answer. Then I woud delete my answer, in order to stremline the argument a little. I don't think I am soo picky!
– prometheos
Mar 10 '18 at 23:41
I would like to add my command as a further option in your answer. Then I woud delete my answer, in order to stremline the argument a little. I don't think I am soo picky!
– prometheos
Mar 10 '18 at 23:41
@prometheos See Can I answer my own question? Our answers can coexist. You can accept your own answer if it suits you better.
– Kamil Maciorowski
Mar 11 '18 at 0:20
@prometheos See Can I answer my own question? Our answers can coexist. You can accept your own answer if it suits you better.
– Kamil Maciorowski
Mar 11 '18 at 0:20
Sorry @Kamil Maciorowski that so much time has passed before me to accept the answer. Just now I urgently need this feature, and this answer is the most useful I can think of to wrap into a function, like - in bash:
probe-subvolume() { btrfs subvolume show $1 &>/dev/null && { true; } || { false; }; }
– prometheos
Jan 14 at 0:05
Sorry @Kamil Maciorowski that so much time has passed before me to accept the answer. Just now I urgently need this feature, and this answer is the most useful I can think of to wrap into a function, like - in bash:
probe-subvolume() { btrfs subvolume show $1 &>/dev/null && { true; } || { false; }; }
– prometheos
Jan 14 at 0:05
@prometheos It's OK. Just curious: in what aspect is
foo && { true; } || { false; }
better than just foo
?– Kamil Maciorowski
Jan 14 at 5:02
@prometheos It's OK. Just curious: in what aspect is
foo && { true; } || { false; }
better than just foo
?– Kamil Maciorowski
Jan 14 at 5:02
" oh yes, I see! The cut-and-paste-devil hit me, somehow. I had first coded for textual ourput, like ` ...|| echo "$1 is either not a subvolume or not existant."; false; }
. Here I used "false" for having the right return code: echo <text> would be allways "sucessful". Then I found that "weniger ist mehr" and removed the text, leaving the rest. You are right: even less ist even better. My shortened code (gets so short that one could do whithout the function!):
probe-subvolume() { btrfs subvolume show $1 &>/dev/null; } ` For @Kamil Maciorowski– prometheos
Jan 15 at 0:51
" oh yes, I see! The cut-and-paste-devil hit me, somehow. I had first coded for textual ourput, like ` ...|| echo "$1 is either not a subvolume or not existant."; false; }
. Here I used "false" for having the right return code: echo <text> would be allways "sucessful". Then I found that "weniger ist mehr" and removed the text, leaving the rest. You are right: even less ist even better. My shortened code (gets so short that one could do whithout the function!):
probe-subvolume() { btrfs subvolume show $1 &>/dev/null; } ` For @Kamil Maciorowski– prometheos
Jan 15 at 0:51
add a comment |
The answer by @Kamil Maciorowski is good. But let me concentrate onto the existence test.
Say I am debugging, and I need to repeat a try, and the target snapshot was already there. Then I was very cautious and sat "bash -e" (i.e. the first error exits my shell. Remember that I must run it as root...). Then I prefer a command that tells me what happened, and then exits. Therefore I do:
btrfs subvolume list /targetdir/@monthly.9 | grep @monthly.8 && echo "$0 ERROR: snapshot /targetdir/@monthly.8 exists already!" && exit
Command "subvolume list " gives no error and lists them all. Then I filter as I need and make my decisions.
Oops! Why did my answer jump to the top? I tought they go chronologically, if they have no votes.
– prometheos
Mar 10 '18 at 23:44
Chronologically if you click "oldest" just above the first answer. This is per user preference and the site is not a forum.
– Kamil Maciorowski
Mar 11 '18 at 0:14
I hope you are aware it does not test exactly for/targetdir/@monthly.8
. I think any subvolume with@monthly.8
in its path (I mean internal path in the filesystem) will triggerecho
, even if this particular subvolume is not reachable in your directory tree at the moment. My solution, on the other hand, tests exactly the object appearing as/targetdir/@monthly.8
in the directory tree.
– Kamil Maciorowski
Mar 11 '18 at 0:38
add a comment |
The answer by @Kamil Maciorowski is good. But let me concentrate onto the existence test.
Say I am debugging, and I need to repeat a try, and the target snapshot was already there. Then I was very cautious and sat "bash -e" (i.e. the first error exits my shell. Remember that I must run it as root...). Then I prefer a command that tells me what happened, and then exits. Therefore I do:
btrfs subvolume list /targetdir/@monthly.9 | grep @monthly.8 && echo "$0 ERROR: snapshot /targetdir/@monthly.8 exists already!" && exit
Command "subvolume list " gives no error and lists them all. Then I filter as I need and make my decisions.
Oops! Why did my answer jump to the top? I tought they go chronologically, if they have no votes.
– prometheos
Mar 10 '18 at 23:44
Chronologically if you click "oldest" just above the first answer. This is per user preference and the site is not a forum.
– Kamil Maciorowski
Mar 11 '18 at 0:14
I hope you are aware it does not test exactly for/targetdir/@monthly.8
. I think any subvolume with@monthly.8
in its path (I mean internal path in the filesystem) will triggerecho
, even if this particular subvolume is not reachable in your directory tree at the moment. My solution, on the other hand, tests exactly the object appearing as/targetdir/@monthly.8
in the directory tree.
– Kamil Maciorowski
Mar 11 '18 at 0:38
add a comment |
The answer by @Kamil Maciorowski is good. But let me concentrate onto the existence test.
Say I am debugging, and I need to repeat a try, and the target snapshot was already there. Then I was very cautious and sat "bash -e" (i.e. the first error exits my shell. Remember that I must run it as root...). Then I prefer a command that tells me what happened, and then exits. Therefore I do:
btrfs subvolume list /targetdir/@monthly.9 | grep @monthly.8 && echo "$0 ERROR: snapshot /targetdir/@monthly.8 exists already!" && exit
Command "subvolume list " gives no error and lists them all. Then I filter as I need and make my decisions.
The answer by @Kamil Maciorowski is good. But let me concentrate onto the existence test.
Say I am debugging, and I need to repeat a try, and the target snapshot was already there. Then I was very cautious and sat "bash -e" (i.e. the first error exits my shell. Remember that I must run it as root...). Then I prefer a command that tells me what happened, and then exits. Therefore I do:
btrfs subvolume list /targetdir/@monthly.9 | grep @monthly.8 && echo "$0 ERROR: snapshot /targetdir/@monthly.8 exists already!" && exit
Command "subvolume list " gives no error and lists them all. Then I filter as I need and make my decisions.
answered Mar 10 '18 at 23:34
prometheosprometheos
33
33
Oops! Why did my answer jump to the top? I tought they go chronologically, if they have no votes.
– prometheos
Mar 10 '18 at 23:44
Chronologically if you click "oldest" just above the first answer. This is per user preference and the site is not a forum.
– Kamil Maciorowski
Mar 11 '18 at 0:14
I hope you are aware it does not test exactly for/targetdir/@monthly.8
. I think any subvolume with@monthly.8
in its path (I mean internal path in the filesystem) will triggerecho
, even if this particular subvolume is not reachable in your directory tree at the moment. My solution, on the other hand, tests exactly the object appearing as/targetdir/@monthly.8
in the directory tree.
– Kamil Maciorowski
Mar 11 '18 at 0:38
add a comment |
Oops! Why did my answer jump to the top? I tought they go chronologically, if they have no votes.
– prometheos
Mar 10 '18 at 23:44
Chronologically if you click "oldest" just above the first answer. This is per user preference and the site is not a forum.
– Kamil Maciorowski
Mar 11 '18 at 0:14
I hope you are aware it does not test exactly for/targetdir/@monthly.8
. I think any subvolume with@monthly.8
in its path (I mean internal path in the filesystem) will triggerecho
, even if this particular subvolume is not reachable in your directory tree at the moment. My solution, on the other hand, tests exactly the object appearing as/targetdir/@monthly.8
in the directory tree.
– Kamil Maciorowski
Mar 11 '18 at 0:38
Oops! Why did my answer jump to the top? I tought they go chronologically, if they have no votes.
– prometheos
Mar 10 '18 at 23:44
Oops! Why did my answer jump to the top? I tought they go chronologically, if they have no votes.
– prometheos
Mar 10 '18 at 23:44
Chronologically if you click "oldest" just above the first answer. This is per user preference and the site is not a forum.
– Kamil Maciorowski
Mar 11 '18 at 0:14
Chronologically if you click "oldest" just above the first answer. This is per user preference and the site is not a forum.
– Kamil Maciorowski
Mar 11 '18 at 0:14
I hope you are aware it does not test exactly for
/targetdir/@monthly.8
. I think any subvolume with @monthly.8
in its path (I mean internal path in the filesystem) will trigger echo
, even if this particular subvolume is not reachable in your directory tree at the moment. My solution, on the other hand, tests exactly the object appearing as /targetdir/@monthly.8
in the directory tree.– Kamil Maciorowski
Mar 11 '18 at 0:38
I hope you are aware it does not test exactly for
/targetdir/@monthly.8
. I think any subvolume with @monthly.8
in its path (I mean internal path in the filesystem) will trigger echo
, even if this particular subvolume is not reachable in your directory tree at the moment. My solution, on the other hand, tests exactly the object appearing as /targetdir/@monthly.8
in the directory tree.– Kamil Maciorowski
Mar 11 '18 at 0:38
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1301671%2ftest-if-btrfs-subvolume-exists%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
My btrfs-progs v4.4 here on ubuntu 16.4 (dayly up to date) seems to overinterprete the man btrfs-subvolume, that says: "... snapshot [-r] <source> <dest>|[<dest>/]<name> ... If only <dest> is given, the subvolume will be named the basename of <source>." It seems to add imlicitly: "If <dest>/name exists already, then create <dest>/<name>/$(basename <source>)". I would call it a bug, or an evil feature.
– prometheos
Mar 8 '18 at 18:10