Last active
October 6, 2015 04:18
-
-
Save daicham/2934926 to your computer and use it in GitHub Desktop.
Redmine Backup Script by Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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