Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.7 > vBulletin 3.7 Add-ons

Reply
 
Thread Tools
Cron job for Files Backup (attachments, avatars, etc.) Details »»
Cron job for Files Backup (attachments, avatars, etc.)
Version: 1.0.2, by Lynne Lynne is offline
Developer Last Online: Oct 2022 Show Printable Version Email this Page

Category: Administrative and Maintenance Tools - Version: 3.7.x Rating:
Released: 03-09-2008 Last Update: 02-19-2009 Installs: 26
Re-useable Code Additional Files Translations  
No support by the author.

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;

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #22  
Old 04-28-2008, 08:51 PM
Jase2 Jase2 is offline
 
Join Date: Dec 2007
Location: USA
Posts: 1,575
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #23  
Old 10-27-2008, 03:38 PM
nerofix nerofix is offline
 
Join Date: Mar 2006
Location: Saarland
Posts: 219
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 ?
Reply With Quote
  #24  
Old 10-27-2008, 03:44 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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/"
Reply With Quote
  #25  
Old 10-27-2008, 03:54 PM
nerofix nerofix is offline
 
Join Date: Mar 2006
Location: Saarland
Posts: 219
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
<?php


error_reporting
(E_ALL & ~E_NOTICE);

if (!
is_object($vbulletin->db))
{
    exit;
}

        
$backupdate date("Y-m-d");
        
//"Y-m-d-H-i-s" to include time

        
$backupdir1 "/my/path/to/useruploads/";

        
//Absolute path to where the files are located
        //ie.  "/home/sitename/public_html/forums/images/avatars/";

        
$files "*";
        
//What file to backup? Use a * to backup all the files
        //inside the folder entered above.

        
$backupto "/my/path/to/backups/";
        
//Absolute path to where to store the backups
        //Make sure to put this outside your root folder
        //Permissions should be 777
        //ie. "/home/sitename/backups/

        
$fileprefix1 "alluseruploads";

        
//This is the prefix that will be added before the date:
        //bak2006-02-25.tar

        
$tararg "-cf";
        
//Here goes the tar arguments.
        // -cf to archive - tar
        // -cjf to archive and bzip2
        // other notes: 
        // -tf to list the contents later on
        // -xf to extract them all later on

//Call the function
backupsus($backupdate,$backupdir1,$backupto,$fileprefix1,$tararg,$files);

function 
backupsus($backupdate,$backupdir1,$backupto,$fileprefix1,$tararg,$files) {

$backupalluseruploads "cd $backupdir1;
    tar 
$tararg {$fileprefix1}{$backupdate}.tar $files;
    mv 
{$fileprefix1}{$backupdate}.tar $backupto";
    
passthru ("$backupalluseruploads");

}

log_cron_action('Profile, Avatar and Attachment Backup Completed'$nextitem);

?>
Would I run into problems to just have 1 backup variable and 1 prefix variable?
Reply With Quote
  #26  
Old 02-20-2009, 04:29 PM
compuminus compuminus is offline
 
Join Date: Apr 2008
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There's a big mistake in the provided mod php file. Currently, it reads:

Code:
$backupattach = "cd $backupdir2;
	tar $tararg {$fileprefix3}{$backupdate}.tar $files;
	mv {$fileprefix3}{$backupdate}.tar $backupto";
	passthru ("$backupattach");
}
When it should really be:

Code:
$backupattach = "cd $backupdir3;
	tar $tararg {$fileprefix3}{$backupdate}.tar $files;
	mv {$fileprefix3}{$backupdate}.tar $backupto";
	passthru ("$backupattach");
}
Otherwise all attachments will not be backed up! Instead, directory 2 (the profile pictures) are just backed up twice...
Reply With Quote
  #27  
Old 02-20-2009, 07:59 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yikes! Good catch! Updated.
Reply With Quote
  #28  
Old 06-07-2009, 07:21 AM
Sunka Sunka is offline
 
Join Date: Mar 2008
Location: Croatia
Posts: 400
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #29  
Old 06-07-2009, 04:24 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #30  
Old 07-04-2009, 12:58 AM
R-D's Avatar
R-D R-D is offline
 
Join Date: Jan 2008
Posts: 158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #31  
Old 07-04-2009, 02:38 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by R-D View Post
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.
I get a "mysql server not found" error every time I do the backup of my attachments (over 12GB). It's a mysql timeout thing - the script does the backup and then the next step is to input a line in the Scheduled Task log and at that point the connection is no longer open and you get the error. It's no big deal - the attachments *are* backed up - there is just no line in the Scheduled Task log to say the script was run.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:14 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08333 seconds
  • Memory Usage 2,320KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete