Logo

dev-resources.site

for different kinds of informations.

[Unity] Publish assets that automatically save backups of files.

Published at
7/12/2024
Categories
backup
unity3d
free
automation
Author
uni928
Categories
4 categories in total
backup
open
unity3d
open
free
open
automation
open
Author
6 person written this
uni928
open
[Unity] Publish assets that automatically save backups of files.

I created a Unity asset that automatically saves Unity backups.
I would like to release it to you in the hope that it will be useful to you.

Please download ver1.0.0 (latest version) from the following site.(it is free asset)
https://assetstore.unity.com/packages/tools/utilities/sephiroth-auto-back-up-monitoring-290378


Description of this asset

Automatically saves a backup every time a file is updated.
No other operations are required other than importing this asset.

The Assets_BackUP folder is automatically generated in the hierarchy where the Assets folder is located.
Every time a file in the Assets folder is updated, a backup is automatically saved there.

The backup file name includes the update date, so if you want to return to a specific point in time, you can identify it by the file name.

If you delete the Assets_BackUP folder, a new Assets_BackUP folder will be regenerated containing only a backup of the current state.
If the Assets_BackUP folder becomes too large, consider deleting it.

This asset will never overwrite any files in the Assets folder.
This asset only touches the Assets_BackUP folder.
Therefore, it is impossible for this asset to cause bugs.
Please use it with confidence.

Introducing the automatically generated Assets_BackUP folder.
Example of generating a backup.


Ver0.0.0 works with the code below.
Ver1.0.0 also has a function to partially delete backup files that are more than 4 business days old, but because the code is long, we will only post the code for Ver0.0.0.

If you create a new SephirothAutoBackUPMonitoring.cs, replace the code with the code below and put it in the Editor folder, it should work in the same state as ver0.0.0.

using System.Threading.Tasks;

namespace SephirothTools
{
    public class SephirothAutoBackUPMonitoring
    {
        private static readonly object Lock = new();
        private static bool isExec = false;
        private static string DateString;

        public const bool isCSharpFileOnly = false;

        [UnityEditor.InitializeOnLoadMethod]
        private static void Exec()
        {
            lock (Lock)
            {
                if (isExec)
                {
                    return;
                }
                isExec = true;
                Task.Run(() => TaskExec(System.DateTime.Now.ToString("yyyyMMdd-HHmmss")));
            }
        }

        private static void TaskExec(string date)
        {
            DateString = date;
            while (true)
            {
                try
                {
                    ExecOneTime();
                }
                catch
                {

                }
                System.Threading.Thread.Sleep(5000); // A thread for SephirothAutoBackUPMonitoring is generated and put into sleep, so the main thread is not stopped.
                if(date != DateString)
                {
                    break;
                }
            }
        }

        private static void ExecOneTime()
        {
            string targetPath = System.IO.Directory.GetCurrentDirectory() + "\\Assets_BackUP";
            if (!System.IO.Directory.Exists(targetPath))
            {
                System.IO.Directory.CreateDirectory(targetPath);
            }

            foreach (string onePath in System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory() + "\\Assets", "*", System.IO.SearchOption.AllDirectories))
            {
                if (isCSharpFileOnly && !onePath.EndsWith(".cs"))
                {
                    continue;
                }

                string oneTargetDirectory = System.IO.Directory.GetCurrentDirectory() + "\\Assets_BackUP" + onePath.Substring((System.IO.Directory.GetCurrentDirectory() + "\\Assets").Length);
                oneTargetDirectory = oneTargetDirectory.Substring(0, oneTargetDirectory.LastIndexOf("\\"));

                string oneTargetFileName = System.IO.File.GetLastWriteTime(onePath).ToString("yyyyMMdd-HHmmss") + "_" + System.IO.Path.GetFileName(onePath);

                string target = oneTargetDirectory + "\\" + oneTargetFileName;

                if (!System.IO.File.Exists(target))
                {
                    string[] pathMove = oneTargetDirectory.Split("\\");
                    string folderPath = pathMove[0];

                    for (int i = 1; i < pathMove.Length; i++)
                    {
                        folderPath = folderPath + "\\" + pathMove[i];
                        if (!System.IO.Directory.Exists(folderPath))
                        {
                            System.IO.Directory.CreateDirectory(folderPath);
                        }
                    }

                    System.IO.File.Copy(onePath, target);
                }
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

We have now released an asset that automatically saves Unity backups.

We hope this will be helpful to your development.
Thank you for reading.

free Article's
30 articles in total
Favicon
How to make an URL to be shorter?
Favicon
how to get free coinmaster coins and spins 2025
Favicon
Orca Slicer Download (Latest 2024)
Favicon
Oxy 1 small - Uncensored LLM trained for (erotic) role-playing
Favicon
Best Thunder Client Alternatives for VSCode in 2024
Favicon
How to Sign PDFs Online for Free with BoldSign
Favicon
AI developer from content writer
Favicon
Get a free SSL certificates for your shared-hosting cPanel domain!
Favicon
How to Get A Toll- Free Number For Your Business in India?
Favicon
5 Free GIS Software Options: Map the World
Favicon
How to Access Detailed Live Stock Charts
Favicon
[Free Premium Account] Video, Free Live Chat & Help Center widget for the websites
Favicon
How to Use AWS Route 53 for Free
Favicon
Free Online AI Report Writer & Generator
Favicon
Unlock the Power of Virtual Machines with AEZA's Terminator
Favicon
Expose html that converts an image into a composition of only certain types of colors.
Favicon
2M users but no money in the bank. Tough times 😔
Favicon
### A Taste of wine without alcoholic free beverages
Favicon
Mackeeper 6.5.5 Crack + Activation Code Full Download
Favicon
Free 32+ APIs for Coders in 2024
Favicon
Introducing Comet: A Free, Cross-Platform Video Converter Powered by FFmpeg
Favicon
Best Free Online Tools for PDF Management in 2024
Favicon
Recommended free and open-source WAF
Favicon
[Unity] Publish assets that automatically organizes folders.
Favicon
[Unity] Publish assets that automatically save backups of files.
Favicon
What is Web4 — And How to Start for Free?
Favicon
Major Update of VidAU.AI: Revolutionize Video Creation with One-Click URL Integration!
Favicon
Free and Open-Source Database Management GUI Tools
Favicon
Organize your business with the best billing software in India
Favicon
The High Price of Ignorance: Paid vs. Free Or Open-Source Software

Featured ones: