Tsukihime 1,489 Posted October 31, 2012 (edited) Data Backup -Tsukihime This script automatically creates a copy of your rvdata2 files and places them in a separate backup folder in your project whenever you testplay your project. Since the files are not touched by the project they should be safe in case of system failure. Note that I haven't tried killing my system while I am performing file operations like saving my project... And if you have lots of data files it might take some time... Download Script: http://db.tt/aDG8DWe1 Spoiler =begin #=============================================================================== ** Data Backup Author: Hime Date: Oct 30, 2012 -------------------------------------------------------------------------------- ** Change log Oct 30 - initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in commercial and non-commercial projects * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script automatically creates a backup whenever you testplay your game. It copies all rvdata2 files in your Data folder into its own subfolder inside a Backup folder. Ideally, even if your system crashes or something happens, you should still have a recent copy available. -------------------------------------------------------------------------------- ** Installation Place this script below Materials and above Main -------------------------------------------------------------------------------- ** Usage Plug and play #=============================================================================== =end $imported = {} if $imported.nil? $imported["TH_DataBackup"] = true #=============================================================================== # ** Configuration #=============================================================================== module Tsuki module Data_Backup Run_Script = true Backup_Path = "Backup/" #=============================================================================== # ** Rest of the script #=============================================================================== # Create a folder for your backup. Based on the time def self.make_folders(path) dir = path.split("/") for i in 0...dir.size unless dir == "." add_dir = dir[0..i].join("/") Dir.mkdir(add_dir) unless Dir.exist?(add_dir) end end end def self.make_backup_folder t = Time.now @dirName = sprintf("%sBackup %04d-%02d-%02d %02dh%02dm%02ds/", Backup_Path, t.year, t.month, t.day, t.hour, t.min, t.sec) make_folders(@dirName) end #--------------------------------------------------------------------------- # TO-DO: improve file path handling #--------------------------------------------------------------------------- def self.backup_file(path) outPath = @dirName + path make_folders(outPath.split("/")[0...-1].join("/")) File.open(outPath, 'wb') {|outFile| File.open(path, 'rb') {|inFile| outFile.write(inFile.read) } } end #--------------------------------------------------------------------------- # TO-DO: recursively back up any folders as well #--------------------------------------------------------------------------- def self.backup_data make_backup_folder Dir.glob("Data/*") {|path| backup_file(path) unless File.directory?(path) } end #--------------------------------------------------------------------------- # Pretty much assumes you don't manually create your own folders or # change the names #--------------------------------------------------------------------------- def self.compare_backup_time now = Time.now last = Dir.glob(Backup_Path + "*")[-1] return true unless last date = File.basename(last.gsub!("Backup", "")) year, month, day, hour, min, sec = [date[0..3], date[4..5], date[6..7], date[8..9], date[10..11], date[12..13]] end def self.needs_backup? true #return true if compare_backup_time end def self.run make_folders(Backup_Path) backup_data if needs_backup? end # run it run if $TEST && Run_Script end end Usage Just paste the script in your project and test-play. You can turn it off if you want. Edited March 6, 2021 by Rikifive dead link, embedded the script in the post 2 Share this post Link to post Share on other sites
littleazo 0 Posted March 16, 2013 Sorry for noob, but... how do you turn it off properly without breaking it? :3 Share this post Link to post Share on other sites
Tsukihime 1,489 Posted March 17, 2013 (edited) What do you mean? There is a configuration option that you can set to false. Edited March 17, 2013 by Tsukihime 1 Share this post Link to post Share on other sites
Chigoo 38 Posted March 18, 2013 (edited) I featured this video in my new YouTube series, check it out! Edited March 18, 2013 by Chigoo Share this post Link to post Share on other sites
littleazo 0 Posted March 18, 2013 Oh, thanks- Sorry... literally the first script I used. I realized it was sort of simple once you used the word false. Thanks Share this post Link to post Share on other sites
Rikifive 3,427 Posted March 6, 2021 Edited Thread: The script link is dead, I have embedded the code in the OP itself. It's a great must-have little script I recommend installing. 1 Share this post Link to post Share on other sites
roninator2 265 Posted March 7, 2021 12 hours ago, Rikifive said: It's a great must-have little script I recommend installing Probably great in its general use and it would be a life saver in most circumstances. I've gotten into the habit of doing my backups manually. Started this 4 years ago. Just last week I found I had some major memory leaks and critical errors with Mithran GOGR script installed. Going through my backups, the issue was there all the way back to two years ago. Restoring from a 2.5 year old backup and manually importing all scripts fixed the issue. Kind of looks like I had a scripts.rvdata2 file error. When I put all of my scripts back in to the old file, everything worked. For anyone not doing backups manually, put this script in. 1 Share this post Link to post Share on other sites