HalestormXV Posted July 19, 2015 Posted July 19, 2015 I made a simple Bash script that executes via cronjob every 2 hours which backup all players inventory be them online or offline. It runs great. Only problem is I can't get the script to clean itself out. Here is the Bash script, anyone have suggestions as to why the self-clean feature is not working? #!/bin/bash # Simple Invetory Backup source=PATH/TO/SOURCE dest=PATH/TO/SOURCE/TO/BACKUP DIRECTORY cp -a -- "$source" "$dest/$(date +"%m-%d-%y-%r")-${source##*/}" find PATH/TO/SOURCE/TO/BACKUP DIRECTORY/* -type f -mtime +1 -exec rm -f {} \; echo "The backup has finished."[/code][/code] Script runs fine and backup the file and correctly timestamps it in the destination directory but doesn't clean delete files that are timestamped over a day old like it should. Thanks in advanced.
Discord Moderator plowmanplow Posted July 19, 2015 Discord Moderator Posted July 19, 2015 A quick fix for your script may be to add the recursive flag (-r) to the rm command in your find statement. You can't "rm" a folder which contains files in Linux/Unix. Adding the recursive flag will make it walk through the folder and remove everything so you can achieve a complete removal. A more robust backup script would possibly archive the players/playerdata folder to a compressed archive to save a ton of space (and allow you to keep more if you wished). It might also instead use rsync to do hard linked backups which would provide the appearance of all full backups (for ease of use) but with deduplication at the file level in order to save significant space.
HalestormXV Posted July 19, 2015 Author Posted July 19, 2015 Good call. I didn't even think about that. As for the archiving process I did think about that and I probably will still add it in. AS it stands now the files that backup the inventory arent even 100kb. I think they sit at around 92 so the space isn't an issue at this moment but in the future as more players come on zipping them might be a good idea so I will probably add that in. I hear wonderful things about rsync. Tbh I would love to use it to make backups of my entire server but I am very unfamilar with it and all of the tutorial/walkthoroughs never seem to be detailed enough. It is something I want to get more familiar with for sure.
Discord Moderator plowmanplow Posted July 19, 2015 Discord Moderator Posted July 19, 2015 Rsync has a couple features which apply very well in the MC server backups domain. When syncing from one location to another, it will only transfer the differences which saves significant time. Additionally, it can do hard link ( --link-dest= ) differential backups which allow you to make what appear to be full backups but area actually hard link (google this) files which means that only the changed files get backed up and the non-changed files get linked to their old versions which saves a ton of space. Here's a script I use for my some of my backups. If it is run every hour you will get 24 "full" backups which don't take up much more space than a single full backup: http://pastebin.com/weLtNReU Feel free to ask me any questions you have about the script. The same process can be used on Windows using Cygwin+rsync
HalestormXV Posted July 20, 2015 Author Posted July 20, 2015 Side note, my inventory backup script works fine now. What I actually had to do for some odd reason was change the mtime to mmin and take the amount of minutes for 2 days and use that value. I do like the zip method though and I will probably switch to that once I get a full Rsync backup method going. Currently I run my servers using Multicraft so I just schedule a nightly backup. But I like the idea of using rsync as a safety net. I see your script here and I have a couple of questions I suppose. What is the performance hit on the server (not necessary the resource usage) but I guess do players actually "feel" when the hourly backup is running? Or is it pretty smooth. Secondly I imagine the initial rsync will probably take quite some time correct? Since everything is new? Third by doing hourly backups I imagine you are essentially grasping all the changes that occur within the day for the 24 hours in a day correct? And because as you said you are using the rsync these changes are quite seemless. But what about in the event of a restore? How does that work?
Discord Moderator plowmanplow Posted July 20, 2015 Discord Moderator Posted July 20, 2015 I run my servers on SSD partitions and the backups save (using rsync) over to separate spindle drives. There is no noticeable performance hit on the servers. If there ever was, one of the nice features of rsync is that you can limit the data rate so as not to negatively impact the server performance. The initial time to rsync is totally dependent on your hardware and how big your full server backup is. I can do a 7G full/initial backup in less than two minutes with no noticeable performance/TPS drop in-game. The way my script runs it performs a full backup every hour and hard links to the last backup. If a file has changed it will copy it over. If a file has not changed it will simply hard link to the previous version (which may itself be a hard link to its previous version, etc.). Each hourly backup appears to be a full backup at the file system level and can be treated as such. Restores, for whatever reason, can be done in part or in whole. Things like player data files which just require the player to be offline can be restored by simply copying a particular file from one of the backups to the "live" version. Files like world region DAT files would need to be copied over while the server itself is offline. A full restore would be as simple as using rsync (with the --delete option) to sync one of the backups to the live version.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now