
OcIc           @   s9  d  Z  d d k l Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 l
 Z
 l Z l Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d a  d a! d2 \ a" a# d a$ g  Z% g  Z& d3 \ a' a( a) d4 \ a* a+ a, d a- d   Z. d   Z/ d   Z0 d	   Z1 d
   Z2 d   Z3 d   Z4 d   Z5 d   Z6 d   Z7 d   Z8 d   Z9 d   Z: d   Z; d   Z< d   Z= d   Z> d   Z? d   Z@ d   ZA d   ZB d   ZC d d  ZD d   ZE d   ZF d   ZG d d   ZH d d! d"  ZI d#   ZJ d$   ZK d%   ZL d&   ZM d'   ZN d(   ZO d)   ZP d*   ZQ d+   ZR d,   ZS d d-  ZT d d.  ZU d/   ZV d0   ZW d1   ZX d S(5   s@   Start (and end) here - read arguments, set global settings, etc.i(   t
   generatorsN(   t   Logt   LoggerErrort   ErrorLogi    c      P   C   s'
  d   } d   } y t  i  |  d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF dG dH dI dJ dK dL dM gJ  \ } a Wn, t  i j
 o } t dN t |   n Xx| D]\ } } | dO j p | dP j o
 dQ a qE| dR j o
 d a qE| dS j o t i dT dU  qE| dV j o
 d a qE| d j o: | d] d^ j o | | d]  a } n d_ a | d` a qE| da j o
 dU a	 qE| db j o t i
 dc |  qE| dd j ph | de j p[ | df j pN | dg j pA | dh j p4 | di j p' | dj j p | dk j p | dl j o t i | | f  qE| dm j o* t i | | f  t i | |   qE| dn j o! t i d  t i t i  qE| dp j o* t i | | f  t i | |   qE| dq j o! t i d  t i t i  qE| dr j o
 dU a qE| ds j o
 | a qE| dt j p | du j p | dv j o t i | | f  qE| dw j o* t i | | f  t i | |   qE| dx j o! t i d  t i t i  qE| dy j o* t i | | f  t i | |   qE| dz j o! t i d  t i t i  qE| d{ j o t i | | f  qE| d| j o | d} a a qE| d~ j o | d a a qE| d j p | d j o
 d* a qE| d j o
 d+ a qE| d j o t i | | f  qE| d j o t i | | f  qE| d j o t i d dU  qE| d j o$ t i d d  t i d d  qE| d j o t i dT d  qE| d j o t i d d  qE| d j o t i d d  qE| d j o t i d |  qE| d j o t i d d  qE| d j o t i d d  qE| d j o t i d d  qE| d j o t i d dU  qE| d j o t i d |  qE| d j o t i d dU  qE| d j o
 dU a qE| d j o t i d dU  qE| d j p | d j o | d a a qE| d j o
 | a qE| d j o
 | a qE| d j o | t _ qE| d j o | a d a qE| d j o t i d d  qE| d j o | |  t _ qE| d j o d t _ | |  t _ qE| d j o d t _ | |  t _ qE| d j p | d j o dD a dU t _ qE| d j o t i d d  qE| d j o | t _ qE| d j o t i |  qE| d j o
 dH a qE| d j o
 | a qE| d j p | d j o t i  |  qE| d j o d \ a a qE| d j o dK | a a qE| d j p | d j o d t i! GHt i" d  qEt i# d |  qEWt d t i! d  d S(   s.   Parse argument list and set global preferencesc         S   s<   y t  |  d  SWn$ t j
 o t i d |   n Xd S(   s7   Helper function for including/excluding filelists belowt   rs   Error opening file %sN(   t   opent   IOErrorR   t
   FatalError(   t   filename(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   sel_fl3   s      c         S   s   t  i t i |   i   i S(   s9   Used below to normalize the security paths before setting(   t   rpatht   RPatht   Globalst   local_connectiont	   normalizet   path(   R   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   normalize_path8   s    s   blr:sv:Vs   backup-modes   calculate-averaget
   carbonfiles   check-destination-dirt   compares   compare-at-time=s   compare-hashs   compare-hash-at-time=s   compare-fulls   compare-full-at-time=s   create-full-paths   current-time=s   exclude=s   exclude-device-filess   exclude-fifoss   exclude-filelist=s   exclude-symbolic-linkss   exclude-socketss   exclude-filelist-stdins   exclude-globbing-filelist=s   exclude-globbing-filelist-stdins   exclude-mirror=s   exclude-other-filesystemss   exclude-regexp=s   exclude-if-present=s   exclude-special-filest   forces   group-mapping-file=s   include=s   include-filelist=s   include-filelist-stdins   include-globbing-filelist=s   include-globbing-filelist-stdins   include-regexp=s   include-special-filess   include-symbolic-linkss   list-at-time=s   list-changed-since=s   list-incrementss   list-increment-sizess   never-drop-aclss   max-file-size=s   min-file-size=s   no-aclss   no-carbonfiles   no-compare-inodes   no-compressions   no-compression-regexp=s   no-eass   no-file-statisticss   no-hard-linkss   null-separators   override-chars-to-quote=s   parsable-outputs   preserve-numerical-idss   print-statisticss   remote-cmd=s   remote-schema=s   remote-tempdir=s   remove-older-than=s   restore-as-of=s	   restrict=s   restrict-read-only=s   restrict-update-only=t   servers   ssh-no-compressions   tempdir=s   terminal-verbosity=s   test-servers   user-mapping-file=s
   verbosity=t   verifys   verify-at-time=t   versions   Bad commandline options: s   -bs   --backup-modet   backups   --calculate-averages   --carbonfilet   carbonfile_activei   s   --check-destination-dirs	   --compares   --compare-at-times   --compare-hashs   --compare-hash-at-times   --compare-fulls   --compare-full-at-timeis   -at-timet   nowi   s   --create-full-paths   --current-timet   current_times	   --excludes   --exclude-device-filess   --exclude-fifoss   --exclude-other-filesystemss   --exclude-regexps   --exclude-if-presents   --exclude-special-filess   --exclude-socketss   --exclude-symbolic-linkss   --exclude-filelists   --exclude-filelist-stdins   standard inputs   --exclude-globbing-filelists!   --exclude-globbing-filelist-stdins   --forces   --group-mapping-files	   --includes   --include-special-filess   --include-symbolic-linkss   --include-filelists   --include-filelist-stdins   --include-globbing-filelists!   --include-globbing-filelist-stdins   --include-regexps   --list-at-times   list-at-times   --list-changed-sinces   list-changed-sinces   -ls   --list-incrementss   --list-increment-sizess   --max-file-sizes   --min-file-sizes   --never-drop-aclst   never_drop_aclss	   --no-aclst   acls_activei    t   win_acls_actives   --no-carbonfiles   --no-compare-inodet   compare_inodes   --no-compressiont   compressions   --no-compression-regexpt   no_compression_regexp_strings   --no-east
   eas_actives   --no-file-statisticst   file_statisticss   --no-hard-linkst   preserve_hardlinkss   --null-separatort   null_separators   --override-chars-to-quotet   chars_to_quotes   --parsable-outputt   parsable_outputs   --preserve-numerical-idss   --print-statisticst   print_statisticss   -rs   --restore-as-ofs   restore-as-ofs   --remote-cmds   --remote-schemas   --remote-tempdirs   --remove-older-thans   remove-older-thans   --no-resource-forkst   resource_forks_actives
   --restricts   --restrict-read-onlys	   read-onlys   --restrict-update-onlys   update-onlys   -ss   --servers   --ssh-no-compressiont   ssh_compressions	   --tempdirs   --terminal-verbositys   --test-servers   --user-mapping-files   -vs   --verbositys   --verifys   --verify-at-times   -Vs	   --versions   rdiff-backup s   Unknown option %ss   Using rdiff-backup version %si   N(   s	   --compares   --compare-at-times   --compare-hashs   --compare-hash-at-times   --compare-fulls   --compare-full-at-time(   s   --exclude-filelists   standard input(   s   --exclude-globbing-filelists   standard input(   s   --include-filelists   standard input(   s   --include-globbing-filelists   standard input(   R   R   ($   t   getoptt   argst   errort   commandline_errort   strt   actionR   t   sett   restore_timestrt   create_full_patht   set_integert   select_optst   appendt   select_filest   syst   stdinR   t   group_mapping_filenamet   Nonet   preserve_numerical_idst
   remote_cmdt   remote_schemat   remote_tempdirt   remove_older_than_stringt   restrict_patht   security_levelR   t   tempfilet   tempdirR   t   setterm_verbosityt   user_mapping_filenamet   setverbosityR   t   exitR   (   t   arglistR	   R   t   optlistt   et   optt   arg(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   parse_cmdlineoptions,   sx   		 														  
 
  
 
  
 
 
 
 
            
  
 
 
 		   
 
   c       	   C   s   h  d g d <d d d d d d d	 g d
 <d d d d d d g d <}  t  t  } | d j o t |  | j o t d  nq t p | d j o q t d  nK t d j p t d j o n- | d j p t |  | j o t d  n d S(   s1   Check to make sure action is compatible with argsR   i    s   list-incrementss   list-increment-sizess   remove-older-thans   list-at-times   list-changed-sinces   check-destination-dirR   i   R   t   restores   restore-as-ofR   s   compare-hashs   compare-fulli   s   No arguments givens-   Switches missing or wrong number of argumentss   test-servers   calculate-averages    Wrong number of arguments given.N(   t   lenR+   R/   R-   (   t   arg_action_dictt   l(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   check_action   s$    	 c         C   sQ   t  o d Sn t |   d j p
 t |   t |  d  o
 d a  n d a  d S(   sA   If no action set, decide between backup and restore at this pointNi   i    RN   R   (   R/   RO   t   AssertionErrort   restore_set_root(   t   rps(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   final_set_action   s      
c         C   s   t  i |  d  d  S(   Ns7   
See the rdiff-backup manual page for more information.(   R   R   (   t   message(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR-      s    c         C   su   t  i d  t i t i  t i d t i  t i	 d t i
  x+ t i D]  } | i i   | i i   qM Wd S(   s7   Set default change ownership flag, umask, relay regexpsi?   t   client_connt   no_compression_regexpN(   t   ost   umaskt   Timet
   setcurtimeR   R   t   SetConnectionst   UpdateGlobalR   t   postset_regexpR    t   connectionst   robustt   install_signal_handlerst   Hardlinkt   initialize_dictionaries(   RU   t   conn(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt
   misc_setup   s    	

 c         C   sK   d   } | t   } |  i i | t  | t  } |  i i | t  d S(   s;   Initialize user and group mapping on destination connectionc         S   sk   |  p d  Sn t i t i |   } y | i   SWn2 t j
 o& } t i d t	 |  |  f  n Xd  S(   Ns$   Error '%s' reading mapping file '%s'(
   R:   R
   R   R   R   t   get_datat   OSErrorR   R   R.   (   R   t   rpRJ   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   get_string_from_file  s      	N(   RE   t
   user_groupt   init_user_mappingR;   R9   t   init_group_mapping(   t   destination_connRk   t   user_mapping_stringt   group_mapping_string(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   init_user_group_mapping  s    	c         C   s  t  d j o- t i t i t i  i   t i d  nt  d j o t |  d |  d  nt  d j o t	 |   nut  d j o t
 |  d  nVt  i d  o t t  |  d |  d  n*t  d j o t |  d  nt  d	 j o t |  d  n t  d
 j o t |  d  n t  d j o t |  d  n t  d j o t |  d  n t  d j o t |    nt t  d j o t |  d |  d d  nK t  d j o t i   n0 t  d j o t |  d  n t d t    d S(   s   Do whatever action saysR   i    R   i   s   calculate-averages   check-destination-dirR   s   list-at-times   list-changed-sinces   list-incrementss   list-increment-sizess   remove-older-thanRN   s   restore-as-ofs   test-serverR   s   Unknown action N(   R/   t
   connectiont   PipeConnectionR7   R8   t   stdoutt   ServerRG   t   Backupt   CalculateAveraget	   CheckDestt
   startswitht   Comparet
   ListAtTimet   ListChangedSincet   ListIncrementst   ListIncrementSizest   RemoveOlderThant   RestoreR^   t   TestConnectionst   VerifyRS   (   RU   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   take_action  s<                 c           C   sN   t  d d  t i   o t i   n t  i   t i p t i   n d S(   s*   Do any last minute cleaning before exitings   Cleaning upi   N(	   R   R   t   isopent   closet   close_logfileR   R   R^   t   CloseConnections(    (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   cleanup'  s     

 c         C   s   y t  |   Wnz t j
 o
   nf t t f j
 oS } t i |  } | o! t i d d  t i |  q t i d d    n Xd S(   s?   Run Main on arglist, suppressing stack trace for routine errorsi   i   N(	   t   Maint
   SystemExitt	   Exceptiont   KeyboardInterruptRb   t   is_routine_fatalR   t	   exceptionR   (   RH   t   exct   errmsg(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   error_check_Main.  s      c         C   s   t  |   t   t i t t t  } t i t	 p d |  t
 t i |  } t |  t |  t |  t   t d j	 o t i t  n d S(   s   Start everything up!t   mirrorN(   RM   RR   R^   t   get_cmd_pairsR+   R=   R<   t   Securityt
   initializeR/   t   mapt
   cmdpair2rpRV   Rg   R   R   t
   return_valR:   R7   RG   (   RH   t   cmdpairsRU   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   ;  s    



 c         C   s	  t  i |  i | i  t |  |  t |  |  | i i i |  t  t i	 o t
 |  } n t | i  t |  t |   t |  |  t oJ t i t  | i i i |  |  t i |  | t  | i i i   n' t i |  |  | i i i |  |  d S(   s6   Backup, possibly incrementally, src_path to dest_path.N(   R^   t   BackupInitConnectionsRf   t   backup_check_dirst   backup_set_rbdirt   fs_abilitiest   backup_set_globalsR   R   R%   t   backup_quoted_rpathsRr   t   backup_final_initt   backup_set_selectt   backup_warn_if_infinite_regresst   prevtimeR\   t   setprevtimeR   t   backup_touch_curmirror_localR   t   Mirror_and_incrementt   incdirt   backup_remove_curmirror_localt   Mirror(   t   rpint   rpout(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyRw   H  s"    
 

c         C   s8   t  i d t i t i   t i t  a t i |   S(   s;   Get QuotedRPath versions of important RPaths.  Return rpoutt   rbdir(   R^   R_   t   FilenameMappingt   get_quotedrpathR   R   R   (   R   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   ]  s    c         C   sT   |  i  i i d j o t d d  t i d  n |  i  i i i	 |  t t
  d S(   s*   Create Select objects on source connectiont   nts-   Symbolic links excluded by default on Windowsi   s   --exclude-symbolic-linksN(   s   --exclude-symbolic-linksN(   Rf   RZ   t   nameR   R4   R5   R:   R   t   SourceStructt   set_source_selectR6   (   R   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   e  s
    c         C   s  | i    oO | i   oA t p t i d | i  q\ t d | i d  | i   n | i    pT y# t o | i   n | i	   Wq t
 i j
 o t i d | i  q Xn |  i    p t i d |  i  n& |  i   p t i d |  i  n | i d  t _ d S(	   s3   Make sure in and out dirs exist and are directoriess,   Destination %s exists and is not a directorys   Deleting %si   s   Unable to create directory %ss"   Source directory %s does not exists   Source %s is not a directorys   rdiff-backup-dataN(   t   lstatt   isdirR   R   R   R   t   deleteR2   t   makedirst   mkdirRZ   R,   t   append_pathR   R   (   R   R   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   m  s$     	 c          C   s   t  i i   ot t  i i   }  t d   |   } t d   |   } t d   |   } | o# t |  d j o t |  d j Sn t S(   s4   Returns true if it looks like initial backup failed.c         S   s   |  i  d   S(   t   current_mirror(   Rz   (   t   x(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   <lambda>  s    c         S   s   |  i  d   S(   t	   error_log(   Rz   (   R   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s    c         S   s   |  i  d   S(   t   mirror_metadata(   Rz   (   R   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s    i   (   R   R   R   t   listdirt   filterRO   t   False(   t   rbdir_filest   mirror_markerst
   error_logst   metadata_mirrors(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   check_failed_initial_backup  s    						c          C   s   t  d d  t i i   }  d |  j o |  i d  t i i d  } y | i i i |  Wq t i	 j
 o t  d d  d Sq t
 i j
 o t  d d  d Sq Xn x; |  D]3 } t i i |  } | i   p | i   q q Wd S(   s1   Clear Globals.rbdir after a failed initial backups-   Found interrupted initial backup. Removing...i   t
   incrementss   Increments dir contains files.i   Ns    Server doesn't support resuming.(   R   R   R   R   t   removeR5   Rf   R
   t   delete_dir_no_filest   RPathExceptionR   t	   ViolationR   R   R   (   R   Rj   t	   file_name(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   fix_failed_initial_backup  s$     c         C   s  y t  i i d  a Wn, t t f j
 o } t i d |  n X| i   p t	 | i
 | i   f  | i   oF | i   o8 y | i d  Wqt j
 o t d d  qXnG t  i i   o  t o t i d | i
  n t   o t   n t  i i   pV y t  i i   Wqjt t f j
 o, } t i d t  i i
 | | i
 f  qjXn t i d t  i  d	 S(
   s   Initialize data dir and loggingR   s    Could not begin backup due to
%si  s.   Cannot change permissions on target directory.i   s   Destination directory

%s

exists, but does not look like a rdiff-backup directory.  Running
rdiff-backup like this could mess up what is currently in it.  If you
want to update or overwrite it, run rdiff-backup with the --force
option.s   Could not create rdiff-backup directory

%s

due to

%s

Please check that the rdiff-backup user can create files and directories in the
destination directory: %sR   N(   R   R   R   R   Ri   R   R   R   R   RS   R   R   R   t   chmodR   R   R   R   R^   R_   (   R   R   R   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s,    & 

&c         C   s   | i  |  i  j	 o d Sn t | i  t |  i  d j o d Sn | i t |  i  d  |  i d j o d Sn t | i t |  i  d i d   } |  i |  } t i i |  p d Sn t	 d | i |  i f d  d S(   s6   Warn user if destination area contained in source areaNi   t   /s   Warning: The destination directory '%s' may be contained in the
source directory '%s'.  This could cause an infinite regress.  You
may need to use the --exclude option.i   (
   Rf   RO   R   t   tuplet   splitt	   new_indexR   t   select_mirrort   SelectR   (   R   R   t   relative_rpout_compst   relative_rpout(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s     # ( ) c          C   sl   t  i i d  }  t i |   } t |  d j p t d t |  f  | o | d i   Sn d Sd S(   s<   Return time in seconds of previous mirror, or None if cannotR   i   s)   Found %s current_mirror rps, expected <=1i    N(	   R   R   R   RN   t   get_inclistRO   RS   t
   getinctimeR:   (   t   incbaset
   mirror_rps(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt   backup_get_mirrortime  s     c         C   s   t  i d j o t  i t i i d   n t |   t   a t t	 i
 j o t  i d  n t i t	 i d t i t i   p t i   n d S(   s<   Open the backup log and the error log, create increments diri    s
   backup.logs   Time of Last backup is not in the past.  This is probably caused
by running two backups in less than a second.  Wait a second a try again.t   compressN(   R   t	   verbosityt   open_logfileR   R   R5   t   checkdest_if_necessaryR   R   R\   t   curtimeR   R   R   t
   curtimestrR   R   R   R   (   R   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s    
	  c         C   su   t  i i d t i d f  } t d | i d  y t i   } Wn d } n X| i	 d | f  | i
   d S(   s  Make a file like current_mirror.time.data to record time

	When doing an incremental backup, this should happen before any
	other writes, and the file should be removed after all writes.
	That way we can tell whether the previous session aborted if there
	are two current_mirror files.

	When doing the initial full backup, the file can be created after
	everything else is in place.

	s   current_mirror.%s.%st   datas   Writing mirror marker %si   t   NAs   PID %s
N(   R   R   R5   R\   R   R   R   RZ   t   getpidt   write_stringt   fsync_with_dir(   R   R   t   mirrorrpt   pid(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s      
c          C   s   t  i i t  i j p t  t i t  i i d   }  t |   d j p t  |  d i	   |  d i	   j  o |  d } n |  d } t
 i   | i   d S(   sD   Remove the older of the current_mirror files.  Use at end of sessionR   i   i    i   N(   R   R   Rf   R   RS   RN   R   R5   RO   R   t   Ct   syncR   (   t   curmir_incst	   older_inc(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s    !

c         C   sr  t  o& t |   o t i d |  i  n t |  | |  y | i i i |  Wn1 t	 t
 f j
 o } d GHt i d |  n Xt | i  t |   }  t t |  |  t i i d t  } | oK y t i t d | } Wq%t i j
 o } t i t |   q%Xn |  i   } t t |  t |  | |  t i t i t  | | |  t d d  d S(	   s   Main restoring function

	Here src_rp should be the source file (either an increment or
	mirror file), dest_rp should be the target rp to be written.

	s*   Could not find rdiff-backup repository at s   
s    Could not begin backup due to
%sR   Rj   s   Restore finishedi   N(   t   restore_root_setRT   R   R   R   t   restore_check_pathsRf   R   t   restore_set_globalsRi   R   Rr   t   restore_init_quotingt   restore_check_backup_dirt   restore_rootR   R   R   t   restore_indexR\   t   genstrtotimeR1   t   TimeExceptionR.   R   t   restore_set_selectt   restore_start_logRN   R   R   (   t   src_rpt   dest_rpt   restore_as_ofR   t	   inc_rpatht   time(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s0    	  c         C   sk   t  i p |  Sn x t  i D] } | i i   q Wt i t  a t i d t i t  i	   t i |   S(   s=   Change rpaths into quoted versions of themselves if necessaryR   (
   R   R%   Ra   R   t   set_init_quote_valsR   R   R^   R_   R   (   R   Rf   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   8  s    
 
  c         C   sw   d   } t  | t  } t oT |  i i i i | t t  t i |   | i i i	 i
 | t t  t i |   n d S(   sk  Set the selection iterator on both side from command line args

	We must set both sides because restore filtering is different from
	select filtering.  For instance, if a file is excluded it should
	not be deleted from the target directory.

	The StringIO stuff is because filelists need to be read and then
	duplicated, because we need two copies of them now.

	c         S   s%   |  i    } |  i   p t  | S(   N(   t   readR   RS   (   t   fpt   buf(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyt	   fp2stringM  s    N(   R   R6   R4   Rf   RN   t   MirrorStructt   set_mirror_selectt	   cStringIOt   StringIOt   TargetStructt   set_target_select(   t	   mirror_rpt   targetR  t   select_data(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   B  s    	c         C   s   y t  i t i i d   Wn5 t t i f j
 o  } t  d t |  d  n Xd |  i	 | i	 t
 i |  f } t  i d j o t  i | d  n t  i d j o t  i |  n d S(   s*   Open restore log file, log initial messages   restore.logs"   Warning - Unable to open logfile: i   s0   Starting restore of %s to %s as it was as of %s.i   i   N(   R   R   R   R   R5   R   R   R   R.   R   R\   t   timetoprettyt   term_verbosityt   log_to_termR   t   log_to_file(   R   R	  R   RJ   t   log_message(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   X  s       c         C   s   | p) |  i    p t i d |  i  q0 n t o@ | i    o3 | i   p | i   o t i d | i  n t o) | i    o | i   o | i   n d S(   sA   Make sure source and destination exist, and have appropriate types   Source file %s does not exists?   Restore target %s already exists, specify --force to overwrite.N(   R   R   R   R   R   R   R   R   (   R   R   t   restoreasof(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   d  s    0	" i   c         C   s   | o& | i    o t i d | i  n t |   } | d j o t i d t i i f  n) | d j o t i d |  i f  n d S(   s5   Make sure backup dir root rpin is in consistent states   File %s does not look like an increment file.

Try restoring from an increment file (the filenames look like
"foobar.2001-09-01T04:49:04-07:00.diff").s3   %s does not appear to be an rdiff-backup directory.i   s   Previous backup to %s seems to have failed.
Rerun rdiff-backup with --check-destination-dir option to revert directory to state before unsuccessful session.N(   t	   isincfileR   R   R   t   checkdest_need_checkR:   R   R   (   t   mirror_rootR   R   t   result(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   n  s    	 c         C   sC  |  i    o |  i   i } n
 |  i } |  i t i j	 o | i d  } n% t i i t i	   |  i d  } | d p
 d } n d } t
 |  } x | | j o t i |  i d i | |    } | i   o% | i   o d | i   j o Pn | i |  i i i d  j o d Sn | d } q Wd S| a t d t i d  t i t i j o t i t  n t i d	 t i d   t i i   p t i d
 t i i  n t | |  } | p | d d j o
 | a nM | d d j p1 t
 |  d j o | d i d  p
 t |  | d a d a d S(   s  Set data dir, restore_root and index, or return None if fail

	The idea here is to keep backing up on the path until we find
	a directory that contains "rdiff-backup-data".  That is the
	mirror root.  If the path from there starts
	"rdiff-backup-data/increments*", then the index is the
	remainder minus that.  Otherwise the index is just the path
	minus the root.

	All this could fail if the increment file is pointed to in a
	funny way, using symlinks or somesuch.

	R   i    i   i   s   rdiff-backup-dataR@   s   Using mirror root directory %si   R   s-   Unable to read rdiff-backup-data directory %sR   N(    R  t
   getincbaseR   Rf   R   R   R   RZ   t   joint   getcwdRO   R
   R   R   t   readableR   t   getR:   R   R   R   t   reset_restrict_pathR^   R_   R   R   R   R   R   Rz   RS   R   (   R   t   relpatht	   pathcompst   min_len_pathcompst   it
   parent_dirt   from_datadir(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyRT     sL     	$ 
 " 		

c         C   s   t  |  d  }  t t  t i t  } t i i d t  } t i	 |  } t i
 i   } t i o t i | | |  GHn t i | | |  GHd S(   s5   Print out a summary of the increments and their timesi   R   N(   t   require_root_setR   R   R   R   R   R   R   RN   R   R  t   get_mirror_timeR&   t   managet   describe_incs_parsablet   describe_incs_human(   Rj   R  R   t   incst   mirror_time(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR~     s    

c         C   s   t  |   p t i d |  i f d  n y  t i i i i t i |  Wn= t	 t
 f j
 o+ } d GHt i d t i i | f  n Xt i o t |   Sn |  Sd S(   s   Make sure rp is or is in a valid rdiff-backup dest directory.

	Also initializes fs_abilities (read or read/write) and quoting and
	return quoted rp if necessary.

	s   Bad directory %s.
s7   It doesn't appear to be an rdiff-backup destination dirs   
s5   Could not open rdiff-backup directory

%s

due to

%sN(   RT   R   R   R   R   R   Rf   R   t   single_set_globalsRi   R   R%   R   (   Rj   t	   read_onlyR   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR!    s    	
 c         C   s$   t  |  d  }  t i t t  GHd S(   s&   Print out a summary of the increments i   N(   R!  R#  R   R   R   (   Rj   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s    c         C   sC   t  d   |   } t i   i |  } | i d t |    GHd S(   s3   Print out the average of the given statistics filesc         S   s   t  i   i |   S(    (   t
   statisticst   StatsObjt   read_stats_from_rp(   Rj   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s    s   Average of %d stat filesN(   R   R*  R+  t   set_to_averaget   get_stats_logstringRO   (   RU   t   statobjst   average_stats(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyRx     s
    		c         C   se   t  |  d  }  t |   t t  } | d j o d Sn t d | f d  t i t i	 |  d S(   s4   Remove all increment files older than a certain timei    Ns!   Actual remove older than time: %si   (
   R!  t   rot_require_rbdir_baset   rot_check_timeR?   R:   R   R#  t   delete_earlier_thanR   R   (   t   rootrpR   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s    
 c      
      sg  y t  i |     Wn+ t  i j
 o } t i t |   n Xg  } t i t i	 i
 d   D] } | | i   qa ~ } t   f d   |  } | p% t d t  i    f d  d Sn | i   d i t t  i |   } t |  d j o) t o! t i d t |  | f  n t |  d j o t d | d  n t d	 | d  | d
 d S(   s;   Check remove older than time_string, return time in secondsR   c            s
   |    j  S(    (    (   t   t(   R   (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s    s+   No increments older than %s found, exiting.i   s   
i   so   Found %d relevant increments, dated:
%s
If you want to delete multiple increments in this way, use the --force.s   Deleting increment at time:
s   Deleting increments at times:
iN(   R\   R   R   R   R   R.   RN   R   R   R   R   R   R   R  R:   t   sortR  R   RO   R   (   t   time_stringR   t   _[1]t   inct   times_in_secst   inc_pretty_time(    (   R   s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR2    s(      5
	c         C   s2   t  d j o! t i d |  i t i f  n d S(   s.   Make sure pointing to base of rdiff-backup dirs]   Increments for directory %s cannot be removed separately.
Instead run on entire directory %s.N(    (   R   R   R   R   R   (   R4  (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR1  	  s    	c         C   s   t  |  d  }  y t i t  } Wn+ t i j
 o } t i t |   n Xt i	 t
  } | i d t
  } x/ |  i i i | | |  D] } | i d GHq Wd S(   s?   List all the files under rp that have changed since restoretimei   R   i    N(   R!  R\   R   R1   R   R   R   R.   R   R   R   R   Rf   RN   R}   t   index(   Rj   t	   rest_timeR   R  t   inc_rpt   rorp(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR}     s       c         C   s   t  |  d  }  y t i t  } Wn+ t i j
 o } t i t |   n Xt i	 t
  } | i d t
  } x. |  i i i | | |  D] } | i   GHq Wd S(   s>   List files in archive under rp that are present at restoretimei   R   N(   R!  R\   R   R1   R   R   R   R.   R   R   R   R   Rf   RN   R|   t   get_indexpath(   Rj   R=  R   R  R>  R?  (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR|     s       c         C   s   t  | d  } | pE y t i t  } Wq[ t i j
 o } t i t |   q[ Xn t i	 t
  } t i i d t
  } t |  |  d j o t i } n; |  d j o t i } n! |  d j p
 t |   t i } | | | | |  a d S(   s  Compare metadata in src_rp with metadata of backup session

	Prints to stdout whenever a file in the src_rp directory has
	different metadata than what is recorded in the metadata for the
	appropriate session.

	Session time is read from restore_timestr if compare_time is None.

	i   R   R   s   compare-hashs   compare-fullN(   R!  R\   R   R1   R   R   R   R.   R   R   R   R   R   R   R   R   R{   t   Compare_hashRS   t   Compare_fullR   (   t   compare_typeR   R   t   compare_timeR   R  R>  t   compare_func(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR{   (  s       
  	c         C   s   t  |  d  }  | pE y t i t  } Wq[ t i j
 o } t i t |   q[ Xn t i	 t
  } t i i d t
  } |  i i i | | |  a d S(   s=   Check the hashes of the regular files against mirror_metadatai   R   N(   R!  R\   R   R1   R   R   R   R.   R   R   R   R   R   R   Rf   R   R   R   (   R   t   verify_timeR   R  R>  (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR   B  s      c         C   s   t  |  d  }  t |   } | d j o t i d |  i f  n/ | d j o! t i d |  i f d d n t |  i  |  i i i	 |   d S(   s!   Check the destination directory, i    s   No destination dir found at %ss)   Destination dir %s does not need checkingt   errlevelN(
   R!  R  R:   R   R   R   Rr   Rf   t   regresst   Regress(   R   t
   need_check(    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyRy   O  s    	c         C   s2  |  i    p t i i    o d
 Sn x- t i i   D] } | d j o Pq7 q7 Wd
 St i i d  } t i |  } | p t i	 d t i i
 f  n t |  d j o d Snw t pN y | d i i i |  Wqt t f j
 o } t i	 d |  qXn t |  d j p
 t d	  d Sd
 S(   sB   Return None if no dest dir found, 1 if dest dir needs check, 0 o/wR%   s
   backup.logR   s  Bad rdiff-backup-data dir on destination side

The rdiff-backup data directory
%s
exists, but we cannot find a valid current_mirror marker.  You can
avoid this message by removing the rdiff-backup-data directory;
however any data in it will be lost.

Probably this error was caused because the first rdiff-backup session
into a new directory failed.  If this is the case it is safe to delete
the rdiff-backup-data directory because there is no important
information in it.

i   i    s=   Could not check if rdiff-backup is currentlyrunning due to
%si   s#   Found too many current_mirror incs!N(   s   chars_to_quotes
   backup.log(   R   R   R   R:   R   R5   RN   R   R   R   R   RO   R   Rf   RH  t
   check_pidsRi   R   RS   (   R   R   t
   curmirrootR   R   (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR  [  s,       	 	c         C   sA   t  |   } | d j o$ t d d  |  i i i |   n d S(   sa   Check the destination dir if necessary.

	This can/should be run before an incremental backup.

	i   sA   Previous backup seems to have failed, regressing destination now.i   N(   R  R   Rf   RH  RI  (   R   RJ  (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pyR     s
    (   NN(   NNN(   NNi    (Y   t   __doc__t
   __future__R    R*   R7   t   reRZ   R  RB   t   logR   R   R   R   R\   R^   t	   selectionRb   R
   R#  R   Rs   RN   R   R   Rd   RH  R   R   R*  R   R:   R/   R2   R<   R=   R   R4   R6   RE   R9   R;   R   R   R   R   RM   RR   RV   R-   Rg   Rr   R   R   R   R   Rw   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   RT   R~   R!  R   Rx   R   R2  R1  R}   R|   R{   R   Ry   R  R   (    (    (    s6   /var/lib/python-support/python2.5/rdiff_backup/Main.pys   <module>   sp   H																	+							
		
	8						
						$