Apple OSX Time Machine

From HaFrWiki
Revision as of 17:47, 28 June 2017 by Hjmf (talk | contribs) (Created page with "{{TOCright}} Time Machine is a great tool for saving the Data on your Mac and/or MacBook. Here are 2 helpful extra's * [[#Delete old backups|Deleting old Backups from Time Ma...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Time Machine is a great tool for saving the Data on your Mac and/or MacBook. Here are 2 helpful extra's

Delete old backups

Time Machine is based on the (Terminal) application tmutil. Deleting old backups on Time Machine Article on DZone [1].

Old backups can be deleted in many ways, the simplest one being the following:

  • Open the Time Machine application when the Finder application is in the foreground.
  • Navigate to the backup to be deleted double clicking on the corresponding position of the ruler on the right side of the screen.
  • Right click with the mouse on the empty space in the Finder.
  • Select Delete Backup.
  • Time Machine will ask you to introduce the super user password and then it will delete the selected backup.

Unfortunately this method is very clumsy if you need to delete many backups.

Another way is using the tmutil command to perform the deletion.
Not only it is simpler, but it will allow you to do it programmatically if you need to.
To delete a backup using tmutil you must perform the following operations:

  • Make sure your time machine backup disk is mounted (the simplest way to do it is opening the Time Machine application).
  • The format of the backup folders created by Time Machine is YYYY-MM-DD-HHmmss.
    If you want to delete a specific backup, you can use the following command: <syntaxhighlight lang="bash">$ sudo tmutil delete /full/path/to/backup/Backups.backupdb/machine/backup-name</syntaxhighlight>

Time Machine currently stores its backups in a folder named after the backed up machine, into the Backups.backupdb folder in the backup disk.
This means that, if your machine is called iMac and your backup disk is mounted on /Volumes/Time Machine Backups, then backups will be located in the following folder:

  • /Volumes/Time Machine Backups/Backups.backupdb/iMac

If you want to delete the 2014-02-02-123411 backup, you must run the following command: <syntaxhighlight lang="bash">$ sudo tmutil delete /Volumes/Time Machine Backups/Backups.backupdb/iMac/2014-02-02-123411</syntaxhighlight>

You can easily make a script, for example, to delete all the backups of a specific month.
The following commands will delete all the backups created in January 2014 (lines were split with \): <syntaxhighlight lang="bash"> $ sudo bash Password: $ for i in /Volumes/Time\ Machine\ Backups/Backups.backupdb/iMac/2014-01* ; \

 do tmutil delete "$i" ; \
 done

</syntaxhighlight>

Content of Time Machine

Often you wanna know what Time Machine has backing up. This Perl script may help you find out.

Usage

To use the tool timedog (installed on /Sources/Perl) do: <syntaxhighlight lang="bash"> $ cd /Volumes/MPRO-TB/Backups.backupdb/Harm’s\ MacBook\ Pro $ /Sources/Perl/timedog -d 5 -l </syntaxhighlight>

Background

By default, timedog will examine the most recent backup, compare it to the one prior, and report all changed files. The -d flag controls the directory depth of reporting, -l disables reporting for symbolic links (for which Time Machine seems to create a new copy of the link each backup). You can also specify a backup of your choice as an argument, though it must also have one prior backup with which to compare.

Source

<syntaxhighlight lang="perl">

  1. !/usr/bin/perl
  2. timedog
  3. J.D. Smith (jdtsmith A@T gmail _dot_ com)
  4. Display the files which time machine backed up in its most recent
  5. backup (or any of your choosing). Uses the fact that Time Machine
  6. creates hard links for unchanged files and directories. Reports old
  7. and new sizes of the changed files, along with the total file count
  8. and backup size.
  9. Usage: timedog [-d depth] [-l] [-n] [latest]
  10. N.B. You must first mount the time machine volume, and change to
  11. the directory containing your time machine backup directories, the
  12. ones named like 2008-07-14-112245/. This can be found in the
  13. directory /Volumes/TM/Backups.backupdb/hostname or similar.
  14. latest: The backup directory for which you'd like to see the
  15. changed contents. Defaults to the most recent (the one
  16. linked to by Latest)
  17. -l: Omit symbolic links from the summary. For whatever
  18. reason, Time Machine creates a new version of a symbolic
  19. link each and every time it backs up.
  20. -n Use simple fixed width formatting, and omit summaries.
  21. -d depth: By default, all files are printed, which can get
  22. lengthy. With this option, summarize changes in
  23. directories only down to the given depth. The number of
  24. files and subdirectories which changed will be reported
  25. as [n].
  26. Example:
  27.  % cd /Volumes/TM/Backups.backupdb/myhost
  28.  % timedog -d 5 -l
  29. LICENSE
  30. Copyright (C) 2008 J.D. Smith
  31. This file is free software; you can redistribute it and/or modify
  32. it under the terms of the GNU General Public License as published
  33. by the Free Software Foundation; either version 2, or (at your
  34. option) any later version.
  35. This File is distributed in the hope that it will be useful, but
  36. WITHOUT ANY WARRANTY; without even the implied warranty of
  37. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  38. General Public License for more details.
  39. You should have received a copy of the GNU General Public License
  40. along with this file; see the file COPYING. If not, write to the
  41. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  42. Boston, MA 02110-1301, USA.


use File::Find; use Fcntl ':mode'; use Getopt::Std;

getopt('d');

sub bytes {

 my $bytes=shift;
 $format=shift || ".1";
 @suff=("B","KB","MB","GB","TB");
 for ($suff=shift @suff; $#suff>=0 and $bytes>=1000.; $suff=shift @suff) {
   $bytes/=1024.;
 }
 return int($bytes) . $suff if int($bytes)==$bytes;
 return sprintf("%${format}f",$bytes) . $suff;

}

sub summarize {

 ($size,$size_old,$old_exists,$name,$cnt)=@_;
 if ($opt_n) {
   printf "%12d %12d %s\n",$old_exists?$size_old:0,$size,$name;
 } else {
   if ($opt_d) { 
     printf "%9s->%9s %6s %s\n",$old_exists?bytes($size_old):"....  ",

bytes($size),$cnt?"[$cnt]":"",$name;

   } else {
     printf "%9s->%9s %s\n",$old_exists?bytes($size_old):"....  ",

bytes($size),$name;

   }
 }

}


opendir DIR,"." or die "Can't open directory."; @files=sort grep {m|[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]+$|} readdir(DIR); die "None or only one Time Machine backups found." if @files == 1;

if (@ARGV) {

 $latest=$ARGV[0];
 $latest=~s|/$||;
 foreach (@files) {
   last if $_ eq $latest;
   $last=$_;
 }
 die "Invalid backup directory" if !defined($last) || $last eq $latest;

} else {

 ($last,$latest)=@files[$#files-1..$#files];

}

print "==> Comparing TM backup $latest to $last\n" unless $opt_n;

my ($old_exists,$rold_exists,$rsize,$rsize_old); $total_size=0; $total_cnt=0;

find({wanted =>

     sub{

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = lstat($_); ($old=$_)=~s/^$latest/$last/; if (-e $old) { ($dev, $ino_old,$mode_old, $nlink,$uid,$gid,$rdev,$size_old) = lstat($old); if ($ino == $ino_old) { # Prune matching $File::Find::prune=1 if -d; return } $old_exists=1; } else {$old_exists=0;}


$total_size+=$size;

$link=S_ISLNK($mode); return if $opt_l && $link;

# Don't include links in the count $total_cnt++; ($name=$_)=~s/^$latest//;

if ($opt_d) { $depth=$name=~tr|/||; $rsize+=$size; $rsize_old+=$size_old if $old_exists; $rcnt++; return if S_ISDIR($mode) || $depth > $opt_d; # Post will handle } $name.="/" if S_ISDIR($mode); $name.="@" if $link; summarize($size,$size_old,$old_exists,$name);

     },
     preprocess =>
     (!$opt_d)?0:
     sub{

$depth=$File::Find::dir=~tr|/||; if ($depth<=$opt_d) { # Starting a new printable directory; zero out sizes $rsize=$rsize_old=$rcnt=0; $rold_exists=-e $File::Find::dir; } @_;

     },
     postprocess =>
     (!$opt_d)?0:
     sub{

$depth=$File::Find::dir=~tr|/||; return if $depth > $opt_d; # This directory is at or below the depth, summarize it ($name=$File::Find::dir)=~s/^$latest//; summarize($rsize,$rsize_old,$rold_exists,$name.'/',$rcnt) if $rsize || $rsize_old; $rsize=$rsize_old=$rcnt=0;

     },
     no_chdir => 1}, $latest);

print "==> Total Backup: $total_cnt changed files/directories, ",

 bytes($total_size,".2"),"\n" unless $opt_n;

</syntaxhighlight>


See also

top

Reference

top

  1. DZone, Shrink your Time Machine Backups, by Enrico Maria Crisostomo