Close

March 13, 2018

ZFStool: Setting up automatic snapshots

root@lightspeed =>  /home => service mysql-server stop                                                        
Stopping mysql.
Waiting for PIDS: 1008.

 root@lightspeed =>  /home => zfs create -o mountpoint=none zroot/var/db                                        
 root@lightspeed =>  /home => zfs list                                             
NAME                       USED  AVAIL  REFER  MOUNTPOINT
zroot                     18.4G  1.66T    88K  /zroot
zroot/ROOT                11.0G  1.66T    88K  none
zroot/ROOT/default        11.0G  1.66T  11.0G  /
zroot/tmp                  532K  1.66T   532K  /tmp
zroot/usr                 2.48G  1.66T    88K  /usr
zroot/usr/home             861M  1.66T   268K  /usr/home
zroot/usr/home/matto       860M  1.66T   860M  /usr/home/matto
zroot/usr/home/syncthing   528K  1.66T   528K  /usr/home/syncthing
zroot/usr/ports           1021M  1.66T  1021M  /usr/ports
zroot/usr/src              661M  1.66T   661M  /usr/src
zroot/var                 4.01M  1.66T    88K  /var
zroot/var/audit             88K  1.66T    88K  /var/audit
zroot/var/crash             88K  1.66T    88K  /var/crash
zroot/var/db                88K  1.66T    88K  none
zroot/var/log              448K  1.66T   448K  /var/log
zroot/var/mail             128K  1.66T   128K  /var/mail
zroot/var/tmp             3.11M  1.66T  3.11M  /var/tmp
zroot/vms                 4.85G  1.66T  4.85G  /vms
zroot/vms/fbsd11-stable    104K  1.66T   104K  /vms/fbsd11-stable

 root@lightspeed =>  /home => mv /var/db/mysql /var/db/mysql-tmp                                                
 root@lightspeed =>  /home => zfs create -o mountpoint=/var/db/mysql zroot/var/db/mysql                         
 root@lightspeed =>  /home => zfs list | grep mysql

NAME                       USED  AVAIL  REFER  MOUNTPOINT
zroot/var/db               176K  1.66T    88K  none
zroot/var/db/mysql          88K  1.66T    88K  /var/db/mysql

 root@lightspeed =>  /home => rsync -avhrP /var/db/mysql-tmp/ /var/db/mysql                                     
sending incremental file list

 root@lightspeed =>  ~mysql => cat /etc/crontab                                                                 
# /etc/crontab - root's crontab for FreeBSD
#
# $FreeBSD: head/etc/crontab 318443 2017-05-18 06:33:55Z ngie $
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
#
#minute hour    mday    month   wday    who     command
#
# Save some entropy so that /dev/random can re-seed on boot.
*/11    *       *       *       *       operator /usr/libexec/save-entropy
#
# Rotate log files every hour, if necessary.
0       *       *       *       *       root    newsyslog
#
# Perform daily/weekly/monthly maintenance.
1       3       *       *       *       root    periodic daily
15      4       *       *       6       root    periodic weekly
30      5       1       *       *       root    periodic monthly
#
# Adjust the time zone if the CMOS clock keeps local time, as opposed to
# UTC time.  See adjkerntz(8) for details.
1,31    0-5     *       *       *       root    adjkerntz -a
#
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
15,30,45 * * * * root /usr/local/sbin/zfs-auto-snapshot frequent  4
0        * * * * root /usr/local/sbin/zfs-auto-snapshot hourly   24
7        0 * * * root /usr/local/sbin/zfs-auto-snapshot daily     7
14       0 * * 7 root /usr/local/sbin/zfs-auto-snapshot weekly    4
28       0 1 * * root /usr/local/sbin/zfs-auto-snapshot monthly  12

 root@lightspeed =>  ~mysql => zfs list                                                                         
NAME                       USED  AVAIL  REFER  MOUNTPOINT
zroot                     18.4G  1.66T    88K  /zroot
zroot/ROOT                11.0G  1.66T    88K  none
zroot/ROOT/default        11.0G  1.66T  11.0G  /
zroot/tmp                  544K  1.66T   544K  /tmp
zroot/usr                 2.48G  1.66T    88K  /usr
zroot/usr/home             861M  1.66T   268K  /usr/home
zroot/usr/home/matto       860M  1.66T   860M  /usr/home/matto
zroot/usr/home/syncthing   528K  1.66T   528K  /usr/home/syncthing
zroot/usr/ports           1021M  1.66T  1021M  /usr/ports
zroot/usr/src              661M  1.66T   661M  /usr/src
zroot/var                 5.68M  1.66T    88K  /var
zroot/var/audit             88K  1.66T    88K  /var/audit
zroot/var/crash             88K  1.66T    88K  /var/crash
zroot/var/db              1.75M  1.66T    88K  none
zroot/var/db/mysql        1.67M  1.66T  1.67M  /var/db/mysql
zroot/var/log              448K  1.66T   448K  /var/log
zroot/var/mail             128K  1.66T   128K  /var/mail
zroot/var/tmp             3.11M  1.66T  3.11M  /var/tmp
zroot/vms                 4.85G  1.66T  4.85G  /vms
zroot/vms/fbsd11-stable    104K  1.66T   104K  /vms/fbsd11-stable

 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=false zroot/var/log                                
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=false zroot/var/mail                               
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=false zroot/var/tmp                                
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=false zroot/var/crash                              
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=false zroot/var/audit                              
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=false zroot/var                                    
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=false zroot/usr/src                                
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=false zroot/usr/ports                              
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=false zroot/tmp                                    
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=true zroot                                         

 root@lightspeed =>  ~mysql => zfs get -t filesystem all | grep auto-snapshot                                   
zroot                     com.sun:auto-snapshot  true                   local
zroot/ROOT                com.sun:auto-snapshot  true                   inherited from zroot
zroot/ROOT/default        com.sun:auto-snapshot  true                   inherited from zroot
zroot/tmp                 com.sun:auto-snapshot  false                  local
zroot/usr                 com.sun:auto-snapshot  true                   inherited from zroot
zroot/usr/home            com.sun:auto-snapshot  true                   inherited from zroot
zroot/usr/home/matto      com.sun:auto-snapshot  true                   inherited from zroot
zroot/usr/home/syncthing  com.sun:auto-snapshot  true                   inherited from zroot
zroot/usr/ports           com.sun:auto-snapshot  false                  local
zroot/usr/src             com.sun:auto-snapshot  false                  local
zroot/var                 com.sun:auto-snapshot  false                  local
zroot/var/audit           com.sun:auto-snapshot  false                  local
zroot/var/crash           com.sun:auto-snapshot  false                  local
zroot/var/db              com.sun:auto-snapshot  false                  inherited from zroot/var
zroot/var/db/mysql        com.sun:auto-snapshot  false                  inherited from zroot/var
zroot/var/log             com.sun:auto-snapshot  false                  local
zroot/var/mail            com.sun:auto-snapshot  false                  local
zroot/var/tmp             com.sun:auto-snapshot  false                  local
zroot/vms                 com.sun:auto-snapshot  true                   inherited from zroot
zroot/vms/fbsd11-stable   com.sun:auto-snapshot  true                   inherited from zroot

 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=true zroot/var/db/mysql                            
 root@lightspeed =>  ~mysql => zfs set com.sun:auto-snapshot=true zroot/var/db                                  

  root@lightspeed =>  ~mysql => zfs list -o creation,name,used,refer,mountpoint -S used -t snap -r                                  
CREATION               NAME                                                               USED  REFER  MOUNTPOINT
Tue Mar 13 16:15 2018  zroot/ROOT/default@zfs-auto-snap_frequent-2018-03-13-16h15         284K  11.0G  -
Tue Mar 13 16:30 2018  zroot/ROOT/default@zfs-auto-snap_frequent-2018-03-13-16h30         264K  11.0G  -
Tue Mar 13 16:30 2018  zroot/usr/home/matto@zfs-auto-snap_frequent-2018-03-13-16h30       108K   860M  -
Tue Mar 13 16:30 2018  zroot@zfs-auto-snap_frequent-2018-03-13-16h30                         0    88K  -
Tue Mar 13 16:30 2018  zroot/usr/home@zfs-auto-snap_frequent-2018-03-13-16h30                0   268K  -
Tue Mar 13 16:30 2018  zroot/usr/home/syncthing@zfs-auto-snap_frequent-2018-03-13-16h30      0   528K  -
Tue Mar 13 16:30 2018  zroot/var/db/mysql@zfs-auto-snap_frequent-2018-03-13-16h30            0  1.67M  -
Tue Mar 13 16:30 2018  zroot/vms@zfs-auto-snap_frequent-2018-03-13-16h30                     0  4.85G  -
Tue Mar 13 16:30 2018  zroot/vms/fbsd11-stable@zfs-auto-snap_frequent-2018-03-13-16h30       0   104K  -