AlphaObeisance
Active Member
Evening ya'll.
Figured I'd share a little story of an experience I had last week.
I've been hosting dedicated servers of a few my family's favorite games for some time now. Terraria being one of the more recent ones. For whatever reason I couldn't get T-Shock to work on the server, and didn't like that the built in backup on the server only saved 1 copy. I got the idea, despite having never written a line of code in my life; that since I couldn't find anything that achieved what I wanted, how I wanted it achieved; I would write my own backup utility.
The first couple days were a lot of trial and error, web searching in order to understand the fundamentals of what I was trying to achive. My code was alllllllll over the place and anytime I ran into a bug, I had one heck of a time seeking it out due to a multitude of syntax issues. At some point I remembered that famous quote by Linus Torvald - “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” and I immediately realized what I was doing wrong.
So I started from scratch on a blank slate in kate. I wrote out my "objectives" exactly what I wanted to accomplish, and the order I wanted to accomplish them. I followed up by defining my variables prior to establishing my functions. I realized that by doing things in this order, instead of trying to manage every single command in one really massive function; I was able to easily execute all of the function sequencially at the end of the code in just a few short lines. It really made the whole process very easy, and I was pretty proud of myself for accomplishing what I'd set out to do.
No doubt there's likely a much easier way to go about doing it; but it functions as intended. I figured I'd share here as it's not only Linux related but Linux Gaming related. And if anyone out there may have a desire for a back up utility; this could do the trick. All that really need be done is one would need to modify the source & destination variables at the top and the code will take care of the rest.
The code runs a check on directories to ensure they can be found. If everything checks out, it compresses the local character data and then moves it to the backup directory; next it does the same thing for the server worlds prior to running a check on all backup directories to count files and delete the oldest to maintain X amount of backups determined by the user; deleting oldest in favor of newest. For those who want it, there's a desktop notification function at the end that uses notify-send to display a "Backup complete" message with an icon and sfx if you choose to set it up (disabled by default); personally I used the Terraria Tree icon.png from the server files, and downloaded the magic mirror SFX from the Terraria Wiki to sound off Backup Complete. Did this latter part mostly just to see if I could.
Couldn't figure out how to play a sound with the notification; so I ended up using CLI VLC to do the trick. It works; but if you're watching anything in VLC at the time the script is run,it'll close out VLC upon exiting the script. Not perfect, but achieves the effect I was looking for lol.
Anyway, figured I'd share. Feel free to use it or change it up or whatever; I tried to write it in such a way that by defining the variables, the script could be used to backup just about anything really, not just Terraria. If you're an experienced programmer and you got any critiques or suggestions, please don't hestitate to chime in. After learning all this, I'm increasingly interested in what else I may be able to program in the future =).
Idk squat about GitHub; so I'm probably doing it wrong. But uploaded there for those who may take interest. I think I opened up a discussion on it(?) but I'm not sure I did it right lol.
The AO Backup Script
Take care, have fun; and be excellent.
-AO
Figured I'd share a little story of an experience I had last week.
I've been hosting dedicated servers of a few my family's favorite games for some time now. Terraria being one of the more recent ones. For whatever reason I couldn't get T-Shock to work on the server, and didn't like that the built in backup on the server only saved 1 copy. I got the idea, despite having never written a line of code in my life; that since I couldn't find anything that achieved what I wanted, how I wanted it achieved; I would write my own backup utility.
The first couple days were a lot of trial and error, web searching in order to understand the fundamentals of what I was trying to achive. My code was alllllllll over the place and anytime I ran into a bug, I had one heck of a time seeking it out due to a multitude of syntax issues. At some point I remembered that famous quote by Linus Torvald - “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” and I immediately realized what I was doing wrong.
So I started from scratch on a blank slate in kate. I wrote out my "objectives" exactly what I wanted to accomplish, and the order I wanted to accomplish them. I followed up by defining my variables prior to establishing my functions. I realized that by doing things in this order, instead of trying to manage every single command in one really massive function; I was able to easily execute all of the function sequencially at the end of the code in just a few short lines. It really made the whole process very easy, and I was pretty proud of myself for accomplishing what I'd set out to do.
No doubt there's likely a much easier way to go about doing it; but it functions as intended. I figured I'd share here as it's not only Linux related but Linux Gaming related. And if anyone out there may have a desire for a back up utility; this could do the trick. All that really need be done is one would need to modify the source & destination variables at the top and the code will take care of the rest.
The code runs a check on directories to ensure they can be found. If everything checks out, it compresses the local character data and then moves it to the backup directory; next it does the same thing for the server worlds prior to running a check on all backup directories to count files and delete the oldest to maintain X amount of backups determined by the user; deleting oldest in favor of newest. For those who want it, there's a desktop notification function at the end that uses notify-send to display a "Backup complete" message with an icon and sfx if you choose to set it up (disabled by default); personally I used the Terraria Tree icon.png from the server files, and downloaded the magic mirror SFX from the Terraria Wiki to sound off Backup Complete. Did this latter part mostly just to see if I could.
Couldn't figure out how to play a sound with the notification; so I ended up using CLI VLC to do the trick. It works; but if you're watching anything in VLC at the time the script is run,it'll close out VLC upon exiting the script. Not perfect, but achieves the effect I was looking for lol.
Anyway, figured I'd share. Feel free to use it or change it up or whatever; I tried to write it in such a way that by defining the variables, the script could be used to backup just about anything really, not just Terraria. If you're an experienced programmer and you got any critiques or suggestions, please don't hestitate to chime in. After learning all this, I'm increasingly interested in what else I may be able to program in the future =).
Idk squat about GitHub; so I'm probably doing it wrong. But uploaded there for those who may take interest. I think I opened up a discussion on it(?) but I'm not sure I did it right lol.
The AO Backup Script
GitHub - Alpha-Obeisance/AO_Scripts: A collection of scripts I've written for the sake of gained knowledge and functionalities of personal prefence.
A collection of scripts I've written for the sake of gained knowledge and functionalities of personal prefence. - GitHub - Alpha-Obeisance/AO_Scripts: A collection of scripts I've written ...
github.com
Take care, have fun; and be excellent.
-AO