For a simple backup system I decided to buy a small memory stick and use it for a local backup. That has the advantage that I will not reduced my storage by backups on the MicroSD card and if the card won’t work one day I have my files on another device that hopefully does its’ job better :-).
Prepare Memory Stick
In my case I started by formating the memory stick to ext4 – that is important because rsnapshot uses hardlinks to store the differences between each backup timestamp.
>> mkdir /mnt/memstick >> blkid
Now you see your devices and their UUIDs. Notice your memory stick UUID and edit the following file /etc/fstab by adding this line:
>> UUID=your_memory_stick_uuid /mnt/memstick ext4 defaults 0 0
This will mount your memory stick automatically on every system start so you do not have to think about mounting after an unplaned restart.
Now we are going to partition our card with fdisk. Keep attention because all existing data on the stick will be removed.
>> fdisk /dev/sda (in my case) >> Command (m for help): d (delete existing partitions, follow wizard) >> Command (m for help): n (create a new Linux partition, follow wizard) >> Command (m for help): w (write partition)
>> mkfs -t ext4 /dev/sda1 >> mount /dev/sda1 /mnt/memstick >> mkdir /mnt/memstick/backups (later used) >> mkdir /mnt/memstick/dbbackups (later used)
For this task I recommend using rsnapshot:
>> apt-get install rsnapshot
Now we can configure rsnapshot which has to be done via modifying the /etc/rsnapshot.conf file at the following entries:
... snapshot_root /mnt/memstick/backups/ ... no_create_root 1 (create automatically backup directories) ... retain daily 7 (create every day) retain weekly 4 (over one month) retain monthly 3 (and hold 3 months back) ... #LOCALHOST backup /var/www/owncloud/ owncloud/ backup /var/www/wordpress/ wordpress/ backup /memstick/dbbackups/ dbbackups/ ...
After modifying you should check your configuration:
>> rsnapshot configtest
Now we are going to create a cron job for our backup system. Open and add the following lines to the /etc/crontab file:
0 1 * * * root /usr/bin/rsnapshot daily (every day at 1am) 0 2 * * 1 root /usr/bin/rsnapshot weekly (once a week at 2am) 0 3 1 * * root /usr/bin/rsnapshot monthly (once a month a 3am) 0 1 * * * root mysqldump -uroot -pMYSQLPASSWORD wordpress /memstick/dbbackups/wordpress.sql 0 1 * * * root mysqldump -uroot -pMYSQLPASSWORD owncloud /memstick/dbbackups/owncloud.sql
Then restart the cron jobs:
>> /etc/init.d/cron restart
Congratulation! You have successfully created a backup system!