![]() |
Cron job for Files Backup (attachments, avatars, etc.)
This is a script meant to run as a Scheduled Task to backup your files if you have your attachments, avatars, etc. in the file system. I have been running it for a couple of years now and given it to a few other vb admins and figured I should share it here as my first Mod. I found the basic part of the script somewhere online a couple of years ago and modified it to work with vbulletin.
Installation: Download the file and modify the variables at the top of the file. The $backupdir should be an absolute path to a folder you wish to backup. Make sure you have a trailing "/" in the path. The $backupto variable is the absolute path to the folder for your backups. It should also have a trailing "/" in the path. Once you fill in those variables, upload the file to your "includes/cron/" directory and go to your Admin CP > Scheduled Tasks > Add New Scheduled Task and create a new task to run the script. I run mine every night (as seen in the attachment). Notes: The script I have attached is made to backup three different directories. You may add more or take away some. But, make sure if you add more at the top ($backupdir4, $fileprefix4) that you add them to the backupsus call. I used to have these variables set as globals in the function, however that stopped working for me after my last upgrade and instead of figuring out if this was a server issue, I simply changed the script to accommodate the change. I have heard that some servers do not allow the use of the passthru() function. I can't help with that as I really don't know anything about servers and their personalities. Also, I assume this will work with windows servers also, but I can't help with that either as I have absolutely no experience with windows servers. This works for me and I hope it works for you to. I'm big on having backups around as it helps me sleep better at night. And, thanks to Boofo for encouraging me to release my first modification! Update: 1.0.1 - I forgot a semi-colon at the end of the $backupdir lines 1.0.2 - was: $backupattach = "cd $backupdir2; s/b : $backupattach = "cd $backupdir3; |
My test site is running 3.7 beta 2 and this script works fine. I don't see any reason why it won't work on the newer versions.
|
Nice! Thanks! *installed*
|
I was thinking of something like this, too. Very handy! Thanks, Lynne. Will install tomorrow, as I currently have a lot on my plate hehe.
|
does/can this also backup the database?
|
No, it doesn't backup the database. You would need a mod such as this for that: https://vborg.vbsupport.ru/showthread.php?t=167276
Installed, Lynne! Thanks. |
Hi Lynne,
Getting the following: Quote:
|
Hmmm, error on line 9. My line 9 is blank.
Make sure your $backupdir4 ends with a trailing slash. Also, make sure when you call the function with "backupsus ($.....)" that the order of the variables in there is the same as the order of variables in the "function backupsus ($.....)" Uh oh... I just noticed I'm missing a semi-colon at the end of the $backupdir2 and $backupdir3. The $backupdir lines should look like this: $backupdir1 = "/my/path/to/avatars/"; $backupdir2 = "/my/path/to/customprofilepics/"; $backupdir3 = "/my/path/to/attachments/"; I'll update the first post with the corrected file. |
All becomes clear... :p
Thanks! |
Quote:
|
Still getting the same error. Hmmm......
|
Here's my attached file, Lynne -- as my email client is acting up lol.
|
For some reason, the lines are getting all run together by your editor and that is why you are getting the error.
For instance, your file line 1 shows: Code:
<?php/*======================================================================*\ Code:
<?php |
I believe that is from:
Code:
/*======================================================================*\ Just ran it again, and it worked. However, files are not showing up. I've cmod the backups folder, still isn't working. This is really strange. |
Quote:
Is the action getting logged, just not producing any output? Are you getting any files output? Did you run it 'as-is' or with your modifications? Do you know if passthru() is an allowable function on your server? |
Quote:
|
Hello Lynne,
Haven't seen if passthru() is enabled on my server, yet (although I think it is) -- but I just noticed the attach, avatars, and profilepics in my forums directory as a .tar file. Any ideas as to why it is saving too my forums directory? I certainly don't have that set for the backup folder. |
Quote:
It sounds like either you don't have the correct path set for the backup directory you want them to be moved to, or you don't have the correct permissions set for the directory. The script makes the backup and then moves the file. Looking at the file you attached above, you have this as your line: $backupto = "/home/user/backups1"; You need to add the trailing slash. It should be: $backupto = "/home/user/backups1/"; |
Hi Lynne,
That is an old file, the new one has the trailing slash. I have also cmod the folder to 777. Any other suggestions..... ? |
Quote:
|
I've now fixed this, Lynne. Somehow, my HTML Editor decided it wanted to play up -- don't know what was wrong, as it was formatting correctly on my computer. Oh well, at least it's fixed now.
Thanks for this, anyway! |
Hey Lynne, thanks for sharing this, I'm very interested in this!
I got a question: I'd like to backup user's profile albums and avatars only. Could you assist me with this a bit please? At the moment, both folders are located under www.domain.com/useruploads ... Now, how to modify the php that it just backup the complete useruploads folder with every subfolder and files? And do I need the complete path /web/mydomain/vbforum/usersuploads or just /useruploads ? |
You need to put the full path in the file, so put in (no quotes, and note the trailing slash which I mentioned you need to have in my notes above) "/web/mydomain/vbforum/usersuploads/"
|
Hey thanks a lot for your answer.. does it also save subfolders then? And can I remove not needed variables from the php file, like this:
PHP Code:
|
There's a big mistake in the provided mod php file. Currently, it reads:
Code:
$backupattach = "cd $backupdir2; Code:
$backupattach = "cd $backupdir3; |
Yikes! Good catch! Updated.
|
One question:
Could use this script to backup forum folder itself? I would like to backup several folders (pictures, attachments, thumbnails), they are all above forum folder (public_html and above) and to backup forum folder too. Is it possible? I asking because, this script have to be in cron folder, and cron folder is in forum folder. |
I have never tested it to backup my forum folders. You actually don't have to put the cron job in the cron folder, you can put it wherever you want as long as you put the correct path in the Scheduled Task.
|
Thanks for the script, Lynne!
It works perfect on the smaller backups (avatars, profile pics, album pics, etc.). Didn't like near 300MB of attachments though but that's probably due to PHP limits on my server. Still highly recommended to anyone else looking to backup their files. :) |
Quote:
|
EDITED:
I had an issue with only 5 of my 8 dirs being backed up but I solved it by chmod 777 for the 3 dirs that weren't getting backed up. Installed and working great on 3.8.4! Thanks! |
All times are GMT. The time now is 05:34 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|