Jump to content
Sign in to follow this  
Tsukihime

Data Backup

Recommended Posts

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 by Rikifive
dead link, embedded the script in the post

Share this post


Link to post
Share on other sites

I featured this video in my new YouTube series, check it out!

Edited by Chigoo

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted