Skip to content

Instantly share code, notes, and snippets.

@hugows
Last active August 29, 2015 14:16
Show Gist options
  • Save hugows/921ff5f736fefdd94901 to your computer and use it in GitHub Desktop.
Save hugows/921ff5f736fefdd94901 to your computer and use it in GitHub Desktop.
package main
import (
"os/exec"
"strings"
"log"
"time"
"fmt"
)
func main() {
repo_folder, err := exec.Command("git", "rev-parse", "--show-toplevel").CombinedOutput()
if err != nil {
log.Fatal(string(repo_folder))
}
norm := strings.Replace(string(repo_folder), ":","", -1)
norm = strings.Replace(norm, "\"","", -1)
norm = strings.Replace(norm, " ","_", -1)
norm = strings.Replace(norm, "/","_", -1)
norm = strings.Replace(norm, "\\","_", -1)
norm = strings.Replace(norm, "\n","", -1)
t := time.Now().Local()
backup_path := fmt.Sprintf("d:/backups/%s_%s.zip", norm, t.Format("20060102150405"))
err = exec.Command("git", "archive", "-o", backup_path, "HEAD").Run()
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment