Skip to content

Instantly share code, notes, and snippets.

@daicham
Last active October 6, 2015 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daicham/2934926 to your computer and use it in GitHub Desktop.
Save daicham/2934926 to your computer and use it in GitHub Desktop.
Redmine Backup Script by Groovy
//Dump from mysql
/* dump ファイルが文字化けしたので コマンドラインから sqldump したほうがよさそう
def mysqldump_process = "/path/to/mysqldump -u redmine -psecret redmine".execute()
new File("redmine.dump").withWriter { writer ->
writer << mysqldump_process.text
}
*/
//Archive dump and attachedfiles
new AntBuilder().zip(destfile: "path/to/backup/redmine-backup." + new Date().format("yyyyMMddHHmmss") + ".zip",
basedir: ".",
includes: "*.dump") {
fileset(dir: "/path/to/redmine") {
include(name: "files/*")
}
}
//Number of keeping backup archive
def KEEP_NUM = 7
def c = 0;
def files = new File("path/to/backup").listFiles().reverse()
files.each {
if (c++ < KEEP_NUM) {
println "Kept${it.canonicalPath}"
} else {
it.delete()
println "Deleted .${it.canonicalPath}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment