PHPackages                             onlyphp/codeigniter3-housekeeping - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. onlyphp/codeigniter3-housekeeping

ActiveLibrary[Database &amp; ORM](/categories/database)

onlyphp/codeigniter3-housekeeping
=================================

A powerful and flexible database archiving solution for CodeIgniter 3 applications. This package helps you manage database growth by providing tools to archive and purge data while maintaining data integrity.

1.0.0(1y ago)04MITPHPPHP &gt;=8.0

Since Feb 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/faizzul95/Codeigniter3Housekeeping)[ Packagist](https://packagist.org/packages/onlyphp/codeigniter3-housekeeping)[ RSS](/packages/onlyphp-codeigniter3-housekeeping/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

🗄️ CodeIgniter 3 Database Archiver
==================================

[](#️-codeigniter-3-database-archiver)

[![Latest Version on Packagist](https://camo.githubusercontent.com/eae0246470bac96b127f47452d4b0b47dc30c6cf87367101360f73db82c5bf0e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6e6c797068702f636f646569676e69746572332d686f7573656b656570696e672e737667)](https://packagist.org/packages/onlyphp/codeigniter3-housekeeping)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/571016382545537b203cbaf4e02fad6f03a665cae0601c705b9562c48d0b2340/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6e6c797068702f636f646569676e69746572332d686f7573656b656570696e672e737667)](https://packagist.org/packages/onlyphp/codeigniter3-housekeeping)

A powerful and flexible database archiving solution for CodeIgniter 3 applications. This package helps you manage database growth by providing tools to archive and purge data while maintaining data integrity.

⚠️ Warning
----------

[](#️-warning)

**DO NOT USE THIS PACKAGE IN PRODUCTION**

This package is under active development and may contain critical bugs. It is primarily intended for personal use and testing. The current version has not undergone rigorous testing and may be unstable.

🚀 Features
----------

[](#-features)

- ✨ Backup and purge operations with transaction support
- 🔄 Parallel processing support for faster execution
- 📊 Progress tracking and integrity verification
- 📝 Detailed logging with customizable paths
- 🎯 Chunk-based processing to manage memory usage
- 🛡️ Support for unique constraints
- 🔌 Multiple database driver support (MySQL, Oracle)
- 🔍 Real-time progress monitoring
- 📈 Performance optimization options

💻 Requirements
--------------

[](#-requirements)

- PHP &gt;= 7.4
- CodeIgniter 3.x
- MySQL 5.7+ or Oracle 11g+
- PHP PCNTL extension (for parallel processing)
- Composer

📦 Installation
--------------

[](#-installation)

### Via Composer

[](#via-composer)

```
composer require onlyphp/codeigniter3-housekeeping
```

### Manual Installation

[](#manual-installation)

1. Download the package
2. Extract to your application/libraries folder
3. Add to your autoload.php:

```
$autoload['libraries'] = array('DatabaseArchiver');
```

🎓 Basic Concepts
----------------

[](#-basic-concepts)

### Operation Modes

[](#operation-modes)

- **Backup Only (BO)**: Only copies data to archive table
- **Purge Only (PO)**: Only deletes data from source table
- **Backup &amp; Purge (BP)**: Copies data then deletes from source

### Processing Methods

[](#processing-methods)

- **Sequential**: Single-threaded processing
- **Parallel**: Multi-threaded processing (Unix/Linux only)

🎯 Usage Examples
----------------

[](#-usage-examples)

### Example 1: Basic Backup Operation

[](#example-1-basic-backup-operation)

Archive records older than 6 months from the 'orders' table:

```
$archiver = new DatabaseArchiver();
$result = $archiver
    ->driver('mysql')
    ->backupFrom('orders')
    ->primaryKey('order_id')
    ->condition('created_at < DATE_SUB(NOW(), INTERVAL 6 MONTH)')
    ->mode('BO')  // Backup Only
    ->run();

print_r($result);
```

### Example 2: Backup and Purge with Unique Constraints

[](#example-2-backup-and-purge-with-unique-constraints)

Archive and delete completed orders while ensuring no duplicate order numbers:

```
$archiver = new DatabaseArchiver();
$result = $archiver
    ->driver('mysql')
    ->backupFrom('orders')
    ->primaryKey('order_id')
    ->uniqueColumns(['order_number'])
    ->condition('status = "completed" AND created_at < DATE_SUB(NOW(), INTERVAL 1 YEAR)')
    ->mode('BP')  // Backup and Purge
    ->chunk(500)  // Process 500 records at a time
    ->run();

// Verify archive integrity
$verification = $archiver->verifyArchive();
print_r($verification);
```

### Example 3: Parallel Processing with Custom Archive Table

[](#example-3-parallel-processing-with-custom-archive-table)

Archive large datasets using parallel processing:

```
$archiver = new DatabaseArchiver();
$result = $archiver
    ->driver('mysql')
    ->backupFrom('transactions')
    ->backupTo('transactions_archive_2023')
    ->primaryKey('transaction_id')
    ->condition('YEAR(transaction_date) = 2023')
    ->mode('BO')
    ->parallel(4)  // Use 4 parallel processes
    ->chunk(1000)
    ->run();

// Monitor progress
$progress = $archiver->getProgress();
print_r($progress);
```

### Example 4: Oracle Database with Debug Mode

[](#example-4-oracle-database-with-debug-mode)

Archive data from an Oracle database with debug logging:

```
$archiver = new DatabaseArchiver();
$result = $archiver
    ->driver('oci')
    ->backupFrom('EMPLOYEES')
    ->primaryKey('EMPLOYEE_ID')
    ->condition('TERMINATION_DATE IS NOT NULL')
    ->mode('BP')
    ->onDebug()  // Enable debug mode
    ->logPath('/custom/path/archive.log')
    ->sqlHint('/*+ PARALLEL(4) */')  // Oracle-specific hint
    ->run();
```

### Example 5: Purge-Only Operation with Memory Management

[](#example-5-purge-only-operation-with-memory-management)

Delete old log entries without backing them up:

```
$archiver = new DatabaseArchiver();
$result = $archiver
    ->driver('mysql')
    ->backupFrom('system_logs')
    ->primaryKey('log_id')
    ->condition('created_at < DATE_SUB(NOW(), INTERVAL 3 MONTH)')
    ->mode('PO')  // Purge Only
    ->chunk(200)  // Smaller chunks to manage memory
    ->run();
```

### Example 6: Interactive Archiving Process with Progress Monitoring

[](#example-6-interactive-archiving-process-with-progress-monitoring)

This example shows a complete archiving process with real-time progress monitoring and verification:

```
class ArchiveManager {
    private $archiver;
    private $maxAttempts = 3;
    private $progressCheckInterval = 5; // seconds

    public function __construct() {
        $this->archiver = new DatabaseArchiver();
    }

    public function runArchiveProcess() {
        try {
            // Configure the archiver
            $this->archiver
                ->driver('mysql')
                ->backupFrom('orders')
                ->primaryKey('order_id')
                ->condition('created_at < DATE_SUB(NOW(), INTERVAL 6 MONTH)')
                ->mode('BP')
                ->chunk(1000)
                ->onDebug();

            // Start the archiving process
            $processId = uniqid('archive_');
            log_message('info', "Starting archive process: {$processId}");

            // Run the archiving process
            $result = $this->archiver->run();

            // Monitor progress until completion
            $this->monitorProgress();

            // Verify the archive
            $verification = $this->verifyArchiveWithRetry();

            return [
                'process_id' => $processId,
                'archive_result' => $result,
                'verification' => $verification
            ];

        } catch (Exception $e) {
            log_message('error', "Archive process failed: " . $e->getMessage());
            throw $e;
        }
    }

    private function monitorProgress() {
        $completed = false;
        $lastPercentage = 0;

        while (!$completed) {
            $progress = $this->archiver->getProgress();

            if ($progress['percentage_complete'] != $lastPercentage) {
                $this->displayProgress($progress);
                $lastPercentage = $progress['percentage_complete'];
            }

            if ($progress['percentage_complete'] >= 100) {
                $completed = true;
                echo "\nArchiving process completed!\n";
            } else {
                sleep($this->progressCheckInterval);
            }
        }
    }

    private function displayProgress($progress) {
        $barLength = 50;
        $completed = round(($progress['percentage_complete'] * $barLength) / 100);
        $remaining = $barLength - $completed;

        $progressBar = "[" .
            str_repeat("=", $completed) .
            ">" .
            str_repeat(" ", $remaining) .
            "]";

        echo sprintf(
            "\rProgress: %s %d%% (%d/%d records)",
            $progressBar,
            $progress['percentage_complete'],
            $progress['archived_records'],
            $progress['total_records']
        );
    }

    private function verifyArchiveWithRetry() {
        $attempts = 0;
        $success = false;
        $lastError = null;

        while ($attempts < $this->maxAttempts && !$success) {
            try {
                $verification = $this->archiver->verifyArchive();

                if ($verification['integrity_status'] === 'ok_complete') {
                    return $verification;
                }

                // Handle different verification statuses
                switch ($verification['integrity_status']) {
                    case 'warning_duplicates_found':
                        throw new Exception("Duplicate records found in archive");
                    case 'warning_incomplete_backup':
                        throw new Exception("Incomplete backup detected");
                    case 'warning_count_mismatch':
                        throw new Exception("Record count mismatch");
                }

                $success = true;
                return $verification;

            } catch (Exception $e) {
                $lastError = $e;
                $attempts++;
                if ($attempts < $this->maxAttempts) {
                    sleep(5); // Wait before retry
                }
            }
        }

        if (!$success) {
            throw new Exception(
                "Archive verification failed after {$this->maxAttempts} attempts. " .
                "Last error: " . $lastError->getMessage()
            );
        }
    }
}

// Usage example:
try {
    $manager = new ArchiveManager();
    $result = $manager->runArchiveProcess();

    echo "\n\nArchive Process Summary:\n";
    echo "Process ID: {$result['process_id']}\n";
    echo "Records Processed: {$result['archive_result']['processed']}\n";
    echo "Execution Time: {$result['archive_result']['execution_time']}\n";
    echo "Memory Usage: {$result['archive_result']['memory']['used']}\n";
    echo "Verification Status: {$result['verification']['integrity_status']}\n";

} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
```

⚙️ Configuration Options
------------------------

[](#️-configuration-options)

MethodDescription`driver(string)`Set database driver ('mysql' or 'oci')`backupFrom(string)`Set source table name`backupTo(string)`Set custom archive table name`primaryKey(string)`Set primary key column`condition(string)`Set WHERE clause for record selection`mode(string)`Set operation mode ('BO', 'PO', or 'BP')`chunk(int)`Set chunk size (100-50000)`parallel(int)`Set number of parallel threads (1-16)`uniqueColumns(array)`Set columns that should be unique in archive`sqlHint(string)`Set SQL optimization hint`logPath(string)`Set custom log file path`onDebug()`Enable debug mode🔍 Monitoring and Verification
-----------------------------

[](#-monitoring-and-verification)

The package provides methods to monitor and verify the archiving process:

```
// Get current progress
$progress = $archiver->getProgress();

// Verify archive integrity
$verification = $archiver->verifyArchive();
```

⚠️ Important Notes
------------------

[](#️-important-notes)

1. Always backup your database before running archiving operations
2. Test the archiving process on a subset of data first
3. Monitor system resources during parallel processing
4. Consider database load and peak hours when scheduling archiving tasks
5. Verify archive integrity after completion

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance40

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

510d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20121045?v=4)[Fahmy Izwan](/maintainers/faizzul95)[@faizzul95](https://github.com/faizzul95)

---

Top Contributors

[![faizzul95](https://avatars.githubusercontent.com/u/20121045?v=4)](https://github.com/faizzul95 "faizzul95 (2 commits)")

---

Tags

mysqloraclecodeignitercodeigniter3housekeeping

### Embed Badge

![Health badge](/badges/onlyphp-codeigniter3-housekeeping/health.svg)

```
[![Health](https://phpackages.com/badges/onlyphp-codeigniter3-housekeeping/health.svg)](https://phpackages.com/packages/onlyphp-codeigniter3-housekeeping)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k605.0M6.8k](/packages/doctrine-dbal)[catfan/medoo

The lightweight PHP database framework to accelerate development

5.0k1.6M205](/packages/catfan-medoo)[nette/database

💾 Nette Database: layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.

5687.0M262](/packages/nette-database)[dibi/dibi

Dibi is Database Abstraction Library for PHP

5014.0M134](/packages/dibi-dibi)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925539.6k13](/packages/envms-fluentpdo)[lichtner/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

930286.0k6](/packages/lichtner-fluentpdo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
