Hello!
I'm pretty new to the whole linux thing and trying to lea by setting up little local headless server using Ubuntu Server 14.04.
One of the things that i need is a automatic backup to exteal HDD every couple of hours. I also want the files to be encrypted in some way.
After some research i figured the best way to do this would be Duplicity. So i followed this guide, skipping the SSH thing.
I ended up with this script: (located in /home/stef2/scripts/backup_notes.sh)
Code:
#!/bin/sh test -x $(which duplicity) || exit 0 . /root/.passphrase export PASSPHRASE $(which duplicity) --encrypt-key 8BA9D028 /server/temp/_Notes file:///media/transcend/backup/
Code:
PASSPHRASE="<my_passphrase_here>"
Code:
$sudo ls -la /root ... -rwx------ 1 root root 22 Apr 18 16:56 .passphrase ...
Code:
$ sudo gpg --list-keys
/home/stef2/.gnupg/pubring.gpg
------------------------------
pub 2048R/8BA9D028 2016-04-19
uid Butt Pirate (aaa) <my_email>
sub 2048R/96870DC1 2016-04-19
And the script works!
When i run it from the shell, it does the backup:
Code:
$ sudo ./backup_notes.sh Synchronizing remote metadata to local cache... Deleting local /home/stef2/.cache/duplicity/db36b31bd40a4143dea5e32e2b87af6b/duplicity-full-signatures.20160419T112620Z.sigtar.gz (not authoritative at backend). Deleting local /home/stef2/.cache/duplicity/db36b31bd40a4143dea5e32e2b87af6b/duplicity-full.20160419T112620Z.manifest (not authoritative at backend). Deleting local /home/stef2/.cache/duplicity/db36b31bd40a4143dea5e32e2b87af6b/duplicity-inc.20160419T112620Z.to.20160419T115851Z.manifest (not authoritative at backend). Deleting local /home/stef2/.cache/duplicity/db36b31bd40a4143dea5e32e2b87af6b/duplicity-inc.20160419T115851Z.to.20160419T122040Z.manifest (not authoritative at backend). Deleting local /home/stef2/.cache/duplicity/db36b31bd40a4143dea5e32e2b87af6b/duplicity-new-signatures.20160419T112620Z.to.20160419T115851Z.sigtar.gz (not authoritative at backend). Deleting local /home/stef2/.cache/duplicity/db36b31bd40a4143dea5e32e2b87af6b/duplicity-new-signatures.20160419T115851Z.to.20160419T122040Z.sigtar.gz (not authoritative at backend). Last full backup date: none No signatures found, switching to full backup. --------------[ Backup Statistics ]-------------- StartTime 1461068463.72 (Tue Apr 19 15:21:03 2016) EndTime 1461068463.78 (Tue Apr 19 15:21:03 2016) ElapsedTime 0.06 (0.06 seconds) SourceFiles 18 SourceFileSize 1978115 (1.89 MB) NewFiles 18 NewFileSize 1978115 (1.89 MB) DeletedFiles 0 ChangedFiles 0 ChangedFileSize 0 (0 bytes) ChangedDeltaSize 0 (0 bytes) DeltaEntries 18 RawDeltaSize 1977435 (1.89 MB) TotalDestinationSizeChange 88880 (86.8 KB) Errors 0
However, i can't get it to work with cron.
As the script only works for root, i figured i need to use the root's crontab. I've also set for it to run every minute, instead of couple hours, just so i can test it faster, and tried to log the process to file.
Heres root's crontab (/tmp/crontab.WX2EPC/crontab):
Code:
# m h dom mon dow command */1 * * * * /home/stef2/scripts/backup_notes.sh > /var/log/backup_test/log1.log 2>&1
Code:
$ cat /var/log/backup_test/log1.log Synchronizing remote metadata to local cache... Copying duplicity-full-signatures.20160419T122103Z.sigtar.gpg to local cache. GPGError: GPG Failed, see log below: ===== Begin GnuPG log ===== gpg: encrypted with RSA key, ID 96870DC1 gpg: decryption failed: secret key not available ===== End GnuPG log =====
Code:
# */1 * * * * /bin/sh /home/stef2/scripts/backup_notes.sh > /var/log/backup_test/log1.log 2>&1 # */1 * * * * root /home/stef2/scripts/backup_notes.sh/ > /var/log/backup_test/log1.log 2>&1 # */1 * * * * cd /home/stef2/scripts && sudo ./backup_notes.sh > /var/log/backup_test/log1.log 2>&1
I've been stuck on this for many hours and could not find any more ideas on google, so please help a noob out! It feels like the solution i'm missing is very simple one, but i just can't get it!
Also, sorry for any mistakes, i'm not a native speaker and don't use forums much.
- Stef
برچسب:
نویسنده: استخدام کار