This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| aa88df13 » | glenc | 2008-05-18 | 1 | # backupsites.py | |
| 2 | """ | ||||
| 3 | Backup Sites | ||||
| 4 | This script will backup all site collections in the specified web application. | ||||
| 5 | |||||
| 6 | Usage: | ||||
| 7 | |||||
| 8 | ipy backupsites.py --url http://myserver --destination \\\\network\share | ||||
| 9 | |||||
| 10 | Arguments: | ||||
| 11 | |||||
| 12 | --url - web application url | ||||
| 13 | --destination - location backups will be saved to | ||||
| 14 | [--overwrite] - if passed, backups will be overwriten if they exist | ||||
| 15 | [--help] - shows this help | ||||
| ba434776 » | glenc | 2008-05-17 | 16 | ||
| aa88df13 » | glenc | 2008-05-18 | 17 | """ | |
| 18 | |||||
| ba434776 » | glenc | 2008-05-17 | 19 | import sp | |
| 20 | from sp import stsadm | ||||
| c238dfcf » | glenc | 2008-05-18 | 21 | import scriptutil | |
| 22 | import sys | ||||
| ba434776 » | glenc | 2008-05-17 | 23 | ||
| 5e914f46 » | glenc | 2008-05-18 | 24 | __all__ = ["backup_sites", "backup_site"] | |
| 25 | |||||
| aa88df13 » | glenc | 2008-05-18 | 26 | # file extension for backup files | |
| ba434776 » | glenc | 2008-05-17 | 27 | FILE_EXTENSION = ".bak" | |
| 28 | |||||
| aa88df13 » | glenc | 2008-05-18 | 29 | ||
| 30 | def main(argv): | ||||
| c238dfcf » | glenc | 2008-05-18 | 31 | args = scriptutil.getargs(argv, ["url=", "destination="], ["overwrite"], __doc__, True) | |
| 32 | backup_sites(args["url"], args["destination"], args.has_key("overwrite")) | ||||
| aa88df13 » | glenc | 2008-05-18 | 33 | ||
| 34 | |||||
| 35 | def backup_sites(url, destination, overwrite=True): | ||||
| ba434776 » | glenc | 2008-05-17 | 36 | """Execute the script""" | |
| 37 | webapp = sp.get_webapplication(url) | ||||
| 38 | |||||
| 39 | # make sure destination has a trailing slash | ||||
| 40 | if destination[-1] != "\\": | ||||
| 41 | destination = destination + "\\" | ||||
| 42 | |||||
| 43 | def do_backup(site): | ||||
| aa88df13 » | glenc | 2008-05-18 | 44 | backup_site(site, destination + _get_backup_filename(site.Url) + FILE_EXTENSION, overwrite) | |
| ba434776 » | glenc | 2008-05-17 | 45 | ||
| 46 | sp.enum_sites(webapp, do_backup) | ||||
| 47 | |||||
| 48 | |||||
| 49 | def _get_backup_filename(url): | ||||
| 50 | url = url.replace("http://", "") | ||||
| 51 | url = url.replace("https://", "") | ||||
| 52 | url = url.replace("/", "_") | ||||
| 53 | url = url.replace(":", ".") | ||||
| 54 | return url | ||||
| 55 | |||||
| 56 | |||||
| aa88df13 » | glenc | 2008-05-18 | 57 | def backup_site(site, filename, overwrite=True): | |
| ba434776 » | glenc | 2008-05-17 | 58 | """Back up a site collection to the specified location""" | |
| 59 | site = sp.get_site(site) | ||||
| 60 | |||||
| c238dfcf » | glenc | 2008-05-18 | 61 | print "Backing up site", site.Url | |
| aa88df13 » | glenc | 2008-05-18 | 62 | stsadm.run("backup", url=site.Url, filename=filename, overwrite=overwrite) | |
| ba434776 » | glenc | 2008-05-17 | 63 | ||
| 64 | |||||
| 65 | |||||
| 66 | if __name__ == '__main__': | ||||
| aa88df13 » | glenc | 2008-05-18 | 67 | main(sys.argv[1:]) | |
| ba434776 » | glenc | 2008-05-17 | 68 | ||







