Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[XP/VX] Backup System

Backup System
by Dargor
Version 1.0


Introduction

I did this script for my FF6 SDK because I was tired of loosing important data. It's really frustrating!
This script will create backups of all your data directory, in case something terrible happens to your project.
Each time you'll test your game, the script will automatically create a backup directory and another directory within it named using the following format:
year_month_day_hour_min_sec
The script will also automatically delete the oldest backup directories if the number of directories exceeds the maximum you have specified.

To use the script, simply copy/paste it above main. You also need to go in Main and add Kernel.make_backup, right under begin.
Don't forget to remove it in the final version of your game!

Features
  • You can choose the path and folder name of the backup directory
  • You can set the maximum number of backup directory to create
  • Compatible with XP and VX!

Script

Code:
 

#==============================================================================

# ** [XP/VX] Backup System

#------------------------------------------------------------------------------

#  © Dargor, 2008

#  01/11/08

#  Version 1.0

#------------------------------------------------------------------------------

#  VERSION HISTORY:

#   - 1.0 (01/11/08), Initial release

#------------------------------------------------------------------------------

#  INSTRUCTIONS:

#   - Paste this above Main

#   - In Main, below begin, add: Kernel.make_backup

#==============================================================================

 

#============================================================================== 

# ** Backup Configuration Module     

#==============================================================================

 

module Backup

  # XP/VX, Set to true when using XP, set to false when using VX

  XP = true

  # Path where all backup folders will be created

  Path = "Data/Backup"

  # Maximum number of backups allowed

  Maximum = 10

end

 

#============================================================================== 

# ** Kernel     

#==============================================================================

 

module Kernel

  #--------------------------------------------------------------------------

  # * Get RPG Maker data extension

  #--------------------------------------------------------------------------

  def self.data_extension

    if Backup::XP

      return 'rxdata'

    else

      return 'rvdata'

    end

  end

  #--------------------------------------------------------------------------

  # * Make Database

  #--------------------------------------------------------------------------

  def self.make_database

    # Load database

    $data_actors        = load_data("Data/Actors.#{self.data_extension}")

    $data_classes       = load_data("Data/Classes.#{self.data_extension}")

    $data_skills        = load_data("Data/Skills.#{self.data_extension}")

    $data_items         = load_data("Data/Items.#{self.data_extension}")

    $data_weapons       = load_data("Data/Weapons.#{self.data_extension}")

    $data_armors        = load_data("Data/Armors.#{self.data_extension}")

    $data_enemies       = load_data("Data/Enemies.#{self.data_extension}")

    $data_troops        = load_data("Data/Troops.#{self.data_extension}")

    $data_states        = load_data("Data/States.#{self.data_extension}")

    $data_animations    = load_data("Data/Animations.#{self.data_extension}")

    # If using XP, load tilesets data

    if Backup::XP

      $data_tilesets      = load_data("Data/Tilesets.#{self.data_extension}")

    end

    $data_common_events = load_data("Data/CommonEvents.#{self.data_extension}")

    $data_system        = load_data("Data/System.#{self.data_extension}")

    $data_scripts       = load_data("Data/Scripts.#{self.data_extension}")

    $data_mapinfos      = load_data("Data/MapInfos.#{self.data_extension}")

    # If using VX, load areas data

    if !Backup::XP

      $data_areas       = load_data("Data/Areas.#{self.data_extension}")

    end

    # Load maps

    self.load_maps

  end

  #--------------------------------------------------------------------------

  # * Load Maps

  #--------------------------------------------------------------------------

  def self.load_maps

    entries = Dir.entries('Data')

    entries.delete('.')

    entries.delete('..')

    $map_list = []

    for entry in entries

      for i in 1..999

        map_id = sprintf("%03d", i)

        $map_list << entry if entry == "Map#{map_id}.#{self.data_extension}"

      end

    end

    $last_data_maps = $data_maps if $data_maps != nil

    $data_maps = {}

    for i in 0...$map_list.size

      path = "Data/" + $map_list[i]

      $data_maps[i + 1] = load_data(path)

    end

  end

  #--------------------------------------------------------------------------

  # * Get RPG Maker data extension

  #--------------------------------------------------------------------------

  def self.save_game_data

    # Create backup directory

    time = Time.new

    year = time.strftime('%Y') 

    month = time.strftime('%b') 

    day = time.strftime('%d')

    hour = time.strftime('%H') 

    min = time.strftime('%M')

    sec = time.strftime('%S')

    folder = "#{year}_#{month}_#{day}_#{hour}_#{min}_#{sec}"

    unless FileTest.directory?("#{Backup::Path}/#{folder}")

      Dir.mkdir("#{Backup::Path}/#{folder}")

    end

    # Save game data

    Kernel.save_data($data_actors,        "#{Backup::Path}/#{folder}/Actors.#{self.data_extension}")

    Kernel.save_data($data_classes,       "#{Backup::Path}/#{folder}/Classes.#{self.data_extension}")

    Kernel.save_data($data_skills,        "#{Backup::Path}/#{folder}/Skills.#{self.data_extension}")

    Kernel.save_data($data_items,         "#{Backup::Path}/#{folder}/Items.#{self.data_extension}")

    Kernel.save_data($data_weapons,       "#{Backup::Path}/#{folder}/Weapons.#{self.data_extension}")

    Kernel.save_data($data_armors,        "#{Backup::Path}/#{folder}/Armors.#{self.data_extension}")

    Kernel.save_data($data_enemies,       "#{Backup::Path}/#{folder}/Enemies.#{self.data_extension}")

    Kernel.save_data($data_troops,        "#{Backup::Path}/#{folder}/Troops.#{self.data_extension}")

    Kernel.save_data($data_states,        "#{Backup::Path}/#{folder}/States.#{self.data_extension}")

    Kernel.save_data($data_animations,    "#{Backup::Path}/#{folder}/Animations.#{self.data_extension}")

    # If using XP, save tilesets data

    if Backup::XP

      Kernel.save_data($data_tilesets,      "#{Backup::Path}/#{folder}/Tilesets.#{self.data_extension}")

    end

    Kernel.save_data($data_common_events, "#{Backup::Path}/#{folder}/CommonEvents.#{self.data_extension}")

    Kernel.save_data($data_system,        "#{Backup::Path}/#{folder}/System.#{self.data_extension}")

    Kernel.save_data($data_scripts,       "#{Backup::Path}/#{folder}/Scripts.#{self.data_extension}")

    Kernel.save_data($data_mapinfos,      "#{Backup::Path}/#{folder}/MapInfos.#{self.data_extension}")

    # If using VX, save areas data

    if !Backup::XP

      Kernel.save_data($data_areas,    "#{Backup::Path}/#{folder}/Areas.#{self.data_extension}")

    end

    # Save maps

    for i in 0...$data_maps.size

      map = $data_maps[i + 1]

      filename = $map_list[i]

      path = "#{Backup::Path}/#{folder}/" + filename

      Kernel.save_data(map, path)

    end

  end

  #--------------------------------------------------------------------------

  # * Make data backup

  #--------------------------------------------------------------------------

  def self.make_backup

    unless FileTest.directory?("#{Backup::Path}")

      Dir.mkdir("#{Backup::Path}")

    end

    self.clear_backup

    self.make_database

    self.save_game_data

    $data_maps = $last_data_maps

  end

  #--------------------------------------------------------------------------

  # * Clear backup

  #--------------------------------------------------------------------------

  def self.clear_backup

    entries = Dir.entries("#{Backup::Path}")

    entries.delete('.')

    entries.delete('..')

    return if entries.size < Backup::Maximum

    for i in 0...(entries.size - Backup::Maximum)

      files = Dir.entries("#{Backup::Path}/#{entries[i]}")

      files.delete('.')

      files.delete('..')

      for file in files

        File.delete("#{Backup::Path}/#{entries[i]}/#{file}")

      end

      Dir.delete("#{Backup::Path}/#{entries[i]}")

    end

  end

end

 

Hope you like it!
-Dargor
 
O_O
oh wow...
this is... great!

I cant remember how many projects I lost in XP each time my pc crashed  ;_;
Awsome work Dargor!

Goodbye security copies! W00t!
 
That's an awesome script. I lost my whole project a month ago because of one of those "terrible things", so this script is the most useful one i've seen in a very long time ^^.
 

Yaxor

Member

Great script Dragor! You dont know what times i lost my projects because of corrupted data or "incidents" lol.

Now, thanks to you, RMXP will be automatically do what we lazy users should do manually :P
 
Wow, I've never seen something like this before. It reminds me of when I thought I had lost all of my custom spritesheets...
Making that script was very inventive of you Dargor, and will probably save many people lots of time otherwise spent on redoing their game. :thumb:
 
Very interesting... in fact, it's a miracle noone attempted this before, as it's the usual way of backupping stuff... but yeah...

And because I always need to make suggestions ;), I think you might add a date check, aka the system keeps one folder per day with 'Maximum' amount of backups inside, as well as a second max constant that defines how many days you want to backup. That'd make it more practical in the way a professional backup system works, since you cannot also rely on having something left, but compare and share between the versions, instead of just having x times the same backup with minimal changes, or optionally huge amounts of data.

Ace work here, dude... keep it up.
 
This would be really handy, I'm using my USB Flash Drive to backup my game, so sometimes I forget to create a backup in my Flash Drive. Anyway, I would need to install this script, and well put a reminder to delete it before releasing the game :D
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top