Windows 에서 백업파일을 Rotate 하여 최근 N일 동안의 백업파일을 유지하도록 하였다.

final DAY_LIMIT  = 14      // N일
final TARGET_DIR = "M:/"


def today   = new Date()
def command = "cmd /c m: & cd \\ & mkdir ${today.format('YYYYMMdd')} & move backup\\*.tib ${today.format('YYYYMMdd')}"
command.execute().waitFor()

new File(TARGET_DIR).eachFile { path ->
    if (path.directory && path.name =~ /201[2-9]\d{4}/) {
        def lastModified = new Date(path.lastModified())
        def diffDay = new Date() - lastModified
        if(diffDay > DAY_LIMIT) {
            // println(lastModified.format("YYYY-mm-dd") + " : ${path}")
            println("cmd /c rd /q /s ${path}")
            "cmd /c rd /q /s ${path}".execute().waitFor()
        }
    }
}

Ruby 버전에 이어서 Groovy 버전도 만들어보았다. 거의 생김새가 비슷한 언어여서, 몇가지만 수정하면 바로 동작한다.

def FOLDER_LIST = [
                    "/path/to1",
                    "/path/to2",
                    "/path/to3",
                    "/path/to4",
                    "/path/to5",
                  ]

def startDate = new Date().format('yyyy/MM/dd HH:mm:ss')

def size_folder_list = []
FOLDER_LIST.each { folder_name ->
    def folder_size = 0
    new File(folder_name).eachFileRecurse { path ->
        folder_size += path.size()
    }
    size_folder_list << "${folder_size}|${folder_name}"
}

size_folder_list = size_folder_list.sort { a, b ->
    (a_size, a_file) = a.split(/\|/)
    (b_size, b_file) = b.split(/\|/)
    // b_size as int <=> a_size as int
    b_size.toInteger() <=> a_size.toInteger()
}

size_folder_list.each { folder ->
    (f_size, f_path) = folder.split(/\|/)
    println("${f_size},${f_path}")
}


def endDate = new Date().format('yyyy/MM/dd HH:mm:ss')
println "\n\n\n"
println "================================================================================"
println "Start Time : $startDate"
println "End   Time : $endDate"
println "================================================================================"

Grails 로 App 을 만들어서, 실행을 하면, App Name 을 콘텍스트로 사용하여 아래와 같이 접속하여야 한다. URL 뒤에 콘텍스트 이름까지 입력하려니 많이 번거롭다.

http://localhost:8080/myApp

사이트를 만들면 ROOT 콘텍스트로 바로 접속할 수 있도록 하여, http://localhost:8080/ 로 접근을 하려는 것이 보통일 것이다.

이를 위해서 2가지 방법이 제공이 되는데, 첫번째는 application.properties 파일에 아래 내용을 추가 하는 것 :

app.context=/

두번째 방법은 Config.groovy 에 아래 내용을 추가하는 것이다

grails.app.context = "/" 

Groovy 스크립트를 실행하면서 현재 실행되고 있는 Groovy 인터프리터의 버전을 알고 싶을 때, 버전에 따라서 아래와 같이 할 수 있으며, 현재 주력 버전이 1.8.6 이고, 곧 2.0.0 도 나올 것이라서 거의 대부분 첫번째 방법으로 사용하면 될 것이다.


[groovy 1.6.6 and 1.7-rc-1 released 이후의 방법]
import groovy.lang.GroovySystem
println GroovySystem.version
// or
println GroovySystem.getVersion()

if (GroovySystem.version >= "1.8.0")
    println "1.8.0 이상"

[예전 방법]
import org.codehaus.groovy.runtime.InvokerHelper  
println InvokerHelper.version 


+ Recent posts