Skip to content

Commit

Permalink
Fixes #19218: backup file are not copied correctly when the destinati…
Browse files Browse the repository at this point in the history
…on directory is on another FS
  • Loading branch information
fanf committed May 4, 2021
1 parent 3468f29 commit e6ac344
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ trait PathComputer {
class PathComputerImpl(
baseFolder: String // "/var/rudder"
, relativeShareFolder: String // "share"
, backupFolder: String // "/var/rudder/backup/"
, backupFolder: Option[String] // "/var/rudder/backup/"
, communityAgentRootPath: String // "/var/rudder/cfengine-community/inputs"
, enterpriseAgentRootPath: String // "/var/cfengine/inputs"
, chainDepthLimit: Int = 20 // max number of relay, to detect cycles
Expand Down Expand Up @@ -97,7 +97,7 @@ class PathComputerImpl(
searchedNodeId
, FilenameUtils.normalize(baseFolder + relativeShareFolder + "/" + path + promisesPrefix)
, FilenameUtils.normalize(baseFolder + relativeShareFolder + "/" + path + promisesPrefix + newPostfix)
, FilenameUtils.normalize(backupFolder + path + promisesPrefix)
, backupFolder.map(x => FilenameUtils.normalize(x + path + promisesPrefix))
)
}
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ final case class AgentNodeWritableConfiguration(
*/
final case class NodePoliciesPaths(
nodeId : NodeId
, baseFolder : String //directory where the file have to be in the end
, newFolder : String //poclicies are temporarly store in a policyName.new directory
, backupFolder: String
, baseFolder : String // /var/rudder/share/xxxx-xxxxx-xxxx/rules/cfengine-community
, newFolder : String // /var/rudder/share/xxxx-xxxxx-xxxx/rules.new/cfengine-community
, backupFolder: Option[String]
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class RemoveNodeServiceImpl(
, ("RUDDER_NODE_ROLES" , nodeInfo.serverRoles.map(_.value).mkString(","))
, ("RUDDER_POLICIES_DIRECTORY_CURRENT" , optNodePaths.map(_.baseFolder).getOrElse(""))
, ("RUDDER_POLICIES_DIRECTORY_NEW" , optNodePaths.map(_.newFolder).getOrElse(""))
, ("RUDDER_POLICIES_DIRECTORY_ARCHIVE" , optNodePaths.map(_.backupFolder).getOrElse(""))
, ("RUDDER_POLICIES_DIRECTORY_ARCHIVE" , optNodePaths.flatMap(_.backupFolder).getOrElse(""))
// for compat in 4.1. Remove in 4.2
, ("RUDDER_NODEID" , nodeInfo.id.value)
, ("RUDDER_NODE_POLICY_SERVER" , nodeInfo.policyServerId.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PathComputerTest extends Specification {
val pathComputer = new PathComputerImpl(
Constants.NODE_PROMISES_PARENT_DIR_BASE
, Constants.NODE_PROMISES_PARENT_DIR
, "/var/rudder/backup/"
, Some("/var/rudder/backup/")
, Constants.CFENGINE_COMMUNITY_PROMISES_PATH
, Constants.CFENGINE_NOVA_PROMISES_PATH
)
Expand All @@ -66,7 +66,7 @@ class PathComputerTest extends Specification {

"the nodeConfig should be " in {
pathComputer.computeBaseNodePath(node1.id, root.id, allNodeConfig.view.mapValues(_.nodeInfo).toMap) must
beEqualTo(Right(NodePoliciesPaths(node1.id,"/var/rudder/share/node1/rules", "/var/rudder/share/node1/rules.new", "/var/rudder/backup/node1/rules")))
beEqualTo(Right(NodePoliciesPaths(node1.id,"/var/rudder/share/node1/rules", "/var/rudder/share/node1/rules.new", Some("/var/rudder/backup/node1/rules"))))
}

// #TODO: migrate in scale-out relay plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object TestSystemData {
val pathComputer = new PathComputerImpl(
SHARE.getParent + "/"
, SHARE.getName
, abstractRoot.getAbsolutePath + "/backup"
, Some(abstractRoot.getAbsolutePath + "/backup")
, rootGeneratedPromisesDir.getAbsolutePath // community will go under our share
, "/" // we don't want to use entreprise agent root path
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ rudder.community.port=5309
# CAUTION: For performance and consistency, it is necessary that the rudder.dir.backup is on the same
# filesystem as /var/rudder/share/ , otherwise the policies change for nodes is non-atomic (move becomes
# copy then delete), and can result to incomplete/partial policies being distributed to nodes.
# Comment that option to disable policy backup.
rudder.dir.backup=/var/rudder/share/backup/

#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,16 @@ object RudderConfig extends Loggable {
x.millis
}
}
val RUDDER_DIR_BACKUP = config.getString("rudder.dir.backup")
val RUDDER_DIR_BACKUP = {
try {
config.getString("rudder.dir.backup").trim match {
case "" => None
case x => Some(x)
}
} catch {
case ex: ConfigException => None
}
}
val RUDDER_DIR_DEPENDENCIES = config.getString("rudder.dir.dependencies")
val RUDDER_DIR_LOCK = config.getString("rudder.dir.lock") //TODO no more used ?
val RUDDER_DIR_SHARED_FILES_FOLDER = config.getString("rudder.dir.shared.files.folder")
Expand Down

0 comments on commit e6ac344

Please sign in to comment.