fix: restore files with original ownership using --chown
rsync -a with sudo restores files as root. Add --chown=$(id -u):$(id -g) to restore commands so files get owned by the calling user.
This commit is contained in:
@@ -227,9 +227,9 @@ bool RsyncManager::restore_files(const std::string& snapshot_path,
|
||||
|
||||
std::string cmd;
|
||||
if (!sudo_password.empty()) {
|
||||
cmd = "echo '" + sudo_password + "' | sudo -S rsync -aAX \"" + src + "\" \"" + dst + "\" 2>&1";
|
||||
cmd = "echo '" + sudo_password + "' | sudo -S rsync -aAX --chown=$(id -u):$(id -g) \"" + src + "\" \"" + dst + "\" 2>&1";
|
||||
} else {
|
||||
cmd = "rsync -aAX \"" + src + "\" \"" + dst + "\" 2>&1";
|
||||
cmd = "rsync -aAX --chown=$(id -u):$(id -g) \"" + src + "\" \"" + dst + "\" 2>&1";
|
||||
}
|
||||
|
||||
g_message("restore cmd: sudo rsync -aAX \"%s\" \"%s\"", src.c_str(), dst.c_str());
|
||||
@@ -293,14 +293,14 @@ bool RsyncManager::restore_full_snapshot(const std::string& snapshot_path,
|
||||
|
||||
std::string cmd;
|
||||
if (!sudo_password.empty()) {
|
||||
cmd = "echo '" + sudo_password + "' | sudo -S rsync -aAX --delete \""
|
||||
cmd = "echo '" + sudo_password + "' | sudo -S rsync -aAX --chown=$(id -u):$(id -g) --delete \""
|
||||
+ snapshot_path + "/\" \"" + restore_dest + "/\" 2>&1";
|
||||
} else {
|
||||
cmd = "rsync -aAX --delete \""
|
||||
cmd = "rsync -aAX --chown=$(id -u):$(id -g) --delete \""
|
||||
+ snapshot_path + "/\" \"" + restore_dest + "/\" 2>&1";
|
||||
}
|
||||
|
||||
g_message("full restore cmd: sudo rsync -aAX --delete \"%s/\" \"%s/\"", snapshot_path.c_str(), restore_dest.c_str());
|
||||
g_message("full restore cmd: sudo rsync -aAX --chown=$(id -u):$(id -g) --delete \"%s/\" \"%s/\"", snapshot_path.c_str(), restore_dest.c_str());
|
||||
|
||||
if (on_progress) {
|
||||
RsyncProgress p;
|
||||
|
||||
Reference in New Issue
Block a user