Skip to content

Commit 0a1fcc0

Browse files
committed
* Custom path to config file can be specified as argument
1 parent be737e1 commit 0a1fcc0

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

changelog.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# 0.x (Unreleased yet)
1+
# 0.5 (17 May, 2015)
22
* Code moved into class
33
* Fix for Ubuntu 15.10 (binaries moved from `/usr/sbin` to `/bin`, now both cases are supported)
44
* Refactoring into multiple methods
55
* Fix for `0` as count of keeping snapshots
66
* Real backups to other partition/drive added, not just snapshots
77
* Some changes in output messages
8+
* Custom path to config file can be specified as argument
89

910
# 0.1 (Nov 20, 2014)
1011
* initial release

just-backup-btrfs.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @author Nazar Mokrynskyi <[email protected]>
99
* @copyright Copyright (c) 2014-2015, Nazar Mokrynskyi
1010
* @license http://opensource.org/licenses/MIT
11-
* @version 0.4
11+
* @version 0.5
1212
*/
1313
class Just_backup_btrfs {
1414
/**
@@ -20,10 +20,13 @@ class Just_backup_btrfs {
2020
*/
2121
protected $binary;
2222
/**
23-
* @param array|null $config
23+
* @param array $config
2424
*/
25-
function __construct ($config = null) {
26-
$this->config = $config ?: json_decode(file_get_contents('/etc/just-backup-btrfs.json'), true);
25+
function __construct ($config) {
26+
if (!$config) {
27+
exit("Incorrect configuration, aborted\n");
28+
}
29+
$this->config = $config;
2730
$this->binary = file_exists('/usr/sbin/btrfs') ? '/usr/sbin/btrfs' : '/bin/btrfs';
2831
}
2932
function backup () {
@@ -392,6 +395,9 @@ protected function snapshots_for_removal ($history_db) {
392395

393396
echo "Just backup btrfs started...\n";
394397

395-
(new Just_backup_btrfs)->backup();
398+
$Just_backup_btrfs = new Just_backup_btrfs(
399+
json_decode(file_get_contents(isset($argv[1]) ? $argv[1] : '/etc/just-backup-btrfs.json'), true)
400+
);
401+
$Just_backup_btrfs->backup();
396402

397403
echo "Just backup btrfs finished!\n";

readme.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sudo php5enmod sqlite3
2222
```
2323

2424
### Usage
25-
Script expects configuration file to be present at location `/etc/just-backup-btrfs.json`, example of such file you can find in this repository.
25+
Script expects configuration file to be present at location `/etc/just-backup-btrfs.json`, example of such file you can find in next section. Also, if you want to use other path to config file - specify it as argument.
2626

2727
There are few ways to run script.
2828
```bash
@@ -36,6 +36,11 @@ sudo ./just-backup-btrfs.php
3636

3737
or mark as executable, rename it to `just-backup-btrfs` (since file can't contain dots in that place) and put into `/etc/cron.daily` to make backups every day.
3838

39+
With custom path to config file:
40+
```bash
41+
sudo ./just-backup-btrfs.php /path/to/config.json
42+
```
43+
3944
Output will be like this:
4045
```
4146
nazar-pc@nazar-pc ~> sudo /just-backup-btrfs.php

0 commit comments

Comments
 (0)